TypeError: this.setState is not a function in reactjs
TypeError: this.setState is not a function in reactjs
我试图在 reselection change.but this.setState() throws error 上设置 属性。
即使我已经绑定了select构造函数的变化。
编辑:当我尝试 select 列 header 中的复选框中的所有行时,它调用 allSelectedRows() 。这里我得到计数但它没有设置
rowSelection = {
onChange: this.onSelectchange,
onSelectAll: (selected, selectedRows, changeRows) => {
console.log(selected, selectedRows, changeRows);
this.allRowsSelected(selected, selectedRows, changeRows);
},
};
constructor(props) {
super(props);
this.state = {
selectedRowKeys: []
}
this.onSelectchange= this.onSelectchange.bind(this);
}
allRowsSelected(selected, selectedRows, changeRows) {
this.setState({ selectedRowKeys: selectedRows.length });
console.log(this.state.selectedRowKeys.length);
}
onSelectchange(record){
console.log(record);
console.log(this.rowSelection);
this.setState({ selectedRowKeys: record });
}
render(){
return(
<Table
rowKey={data._id}
columns={this.columns1}
rowSelection={this.rowSelection}
expandedRowRender={(record, index, indent, expanded) =>
this.expanding(record, expanded)
}
onExpand={this.onExpand}
dataSource={data} />
)
}
你能更新你的代码如下吗
rowSelection = {
onChange: (record)=> this.onSelectchange(record),
};
我不确定,但我想这对你有用!
如果不起作用请告诉我。
我试图在 reselection change.but this.setState() throws error 上设置 属性。 即使我已经绑定了select构造函数的变化。
编辑:当我尝试 select 列 header 中的复选框中的所有行时,它调用 allSelectedRows() 。这里我得到计数但它没有设置
rowSelection = {
onChange: this.onSelectchange,
onSelectAll: (selected, selectedRows, changeRows) => {
console.log(selected, selectedRows, changeRows);
this.allRowsSelected(selected, selectedRows, changeRows);
},
};
constructor(props) {
super(props);
this.state = {
selectedRowKeys: []
}
this.onSelectchange= this.onSelectchange.bind(this);
}
allRowsSelected(selected, selectedRows, changeRows) {
this.setState({ selectedRowKeys: selectedRows.length });
console.log(this.state.selectedRowKeys.length);
}
onSelectchange(record){
console.log(record);
console.log(this.rowSelection);
this.setState({ selectedRowKeys: record });
}
render(){
return(
<Table
rowKey={data._id}
columns={this.columns1}
rowSelection={this.rowSelection}
expandedRowRender={(record, index, indent, expanded) =>
this.expanding(record, expanded)
}
onExpand={this.onExpand}
dataSource={data} />
)
}
你能更新你的代码如下吗
rowSelection = {
onChange: (record)=> this.onSelectchange(record),
};
我不确定,但我想这对你有用! 如果不起作用请告诉我。