[英]React setState error anyone help ? minified error
I have a dual list box but when i click the left or right button the item's transfer the other side its okay but ı got a error message in the console.我有一个双列表框,但是当我单击向左或向右按钮时,该项目的传输到另一侧还可以,但我在控制台中收到一条错误消息。 When I Clear the rightClick this.setState error is gone but items never change or transfer other side.
当我清除 rightClick this.setState 错误消失但项目永远不会改变或转移到另一边。 What I have to do?
我必须做什么? I analyze the error everyone says NODE_ENV=development I try but not working for me?
我分析每个人都说 NODE_ENV=development 我尝试但不适合我的错误? I describe the this.setState() like that normally ı define this.setState({}) but ı cant define like that ı get a error message again anyone help?
我通常这样描述 this.setState() 我定义 this.setState({}) 但我不能这样定义我再次收到错误消息有人帮忙吗?
this.state = {
role: ['admin' , 'user' , 'subscriber' , 'superadmin'],
activeRole:['admin1'],
selectedIndex : 0,
selectedItem : ''
};
menuClick = (activeItem,index) =>{
this.selectedIndex = index;
this.selectedItem = activeItem;
// activeItem 1. arrayda varsa düğmeyi kapat
// yoksa diğer düüme"112453
// console.log('activeItem' + activeItem);
// console.log('index' + index);
}
rightClick = ()=>{
console.log(this.selectedIndex);
console.log(this.state.role);
this.setState(
this.state.role.splice(this.selectedIndex, 1),
this.state.activeRole.push(this.selectedItem)
);
}
leftClick = ()=>{
console.log(this.selectedIndex);
console.log(this.state.role);
this.setState(
this.state.activeRole.splice(this.selectedIndex, 1),
this.state.role.push(this.selectedItem)
);
}
update your functions as bellow如下更新您的功能
rightClick = () => {
console.log(this.selectedIndex);
console.log(this.state.role);
this.setState({
role: this.state.role.splice(this.selectedIndex, 1),
activeRole: this.state.activeRole.push(this.selectedItem)
});
}
leftClick = () => {
console.log(this.selectedIndex);
console.log(this.state.role);
this.setState({
activeRole: this.state.activeRole.splice(this.selectedIndex, 1),
role: this.state.role.push(this.selectedItem)
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.