reactjs-React中的setState在事件gridjs中不起作用
发布时间:2022-05-13 14:39:33 212
相关标签: # node.js
我在和gridjs
库中有一个单击事件,当修改状态时它不会这样做。知道会是什么吗?
componentDidMount() {
this.consultaAPI();
localStorage.removeItem("excludeIDS")
this.grid.current.instance.on('cellClick', (...item) => {
console.log(this)
if(typeof item[1].data === "boolean"){
console.log(item)
console.log(item[3]._cells[1].data)
//console.log(row[1]._cells[1].data);
let newID = JSON.stringify(item[3]._cells[1].data)
if(item[1].data && this.state.todos){
if(localStorage.getItem("excludeIDS")!=null){
let ids = JSON.parse(localStorage.getItem("excludeIDS"))
if(!ids.includes(newID)){
ids.push(newID)
localStorage.setItem("excludeIDS", JSON.stringify(ids))
console.log("add id")
this.setState({count:this.state.count-1})
}
}else{
console.log("created collection")
let ids =[newID]
localStorage.setItem("excludeIDS",JSON.stringify(ids))
this.setState({count:this.state.count-1})
}
}else if(!item[1].data && this.state.todos){
console.log("remove id of collections")
let ids = JSON.parse(localStorage.getItem("excludeIDS"))
ids.splice(ids.indexOf(newID),1)
localStorage.setItem("excludeIDS",JSON.stringify(ids))
this.setState({count:this.state.count+1})
}
}
});
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报