我在该州有两个数组,并且都有 id。
arrOne = [2,6,8]
arrTwo = [3, 8, 4]
如果某个数组具有相同的值(在本例中为 8),我想禁用具有相同值的所有按钮。
我尝试了这样的方法,但我没有得到它
button = () => {
const checkId = this.state.arrOne.filter(arr => arr.includes(this.state.arrTwo.map(data => data.id))
if(checkedId){
return <Button disable />
}
return <Button />
}
render(){
this.button()
}
我有包含所有数组的按钮,如果数组一等于数组二,我想禁用这个相等的特定按钮 有什么想法吗?
感谢您的帮助
最佳答案
这应该有帮助。
const isDisabled = this.state.arrOne.some(item => this.state.arrTwo.includes(item));
return <Button disabled={isDisabled} />;
关于javascript - 比较两个数组,如果 id 相等则禁用元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58540193/