1、
render(){
let { list,cityList,ischecked,selectedRowKeys,selectedRows} = this.state
const rowSelection = {
selectedRowKeys,
onChange:this.handleRowSelectChange,
onSelect: (record, selected, selectedRows) => {
// console.log(record, selected, selectedRows);
},
onSelectAll: (selected, selectedRows, changeRows) => {
// console.log(selected, selectedRows, changeRows,taskList);
},
};
return(
<Checkbox onChange={this.selectAll} checked={ischecked}>全选</Checkbox>
) }
2、
selectAll=()=>{
let ischecked=true
let {list,selectedRows,selectedRowKeys} = this.state;
if(list.length === selectedRows.length){
ischecked=false
this.handleRowSelectChange([],[]);
}else{
ischecked=true
//把索引数组里的值由String转换成Number
const keys = Object.keys(list)
const index = [];
keys.forEach(item=>{
index.push(Number(item))
});
this.handleRowSelectChange(index,list)
}
this.setState({ischecked:ischecked})
}
handleRowSelectChange = (selectedRowKeys, selectedRows) => {
// 在 state中 维护这个状态
this.setState({
selectedRowKeys: selectedRowKeys,
selectedRows: selectedRows,
});
taskList = selectedRows
};