我正在使用react-checkbox-tree(Reactjs)来创建一个多重选择树,在该树中,我试图向用户提供访问权限,并且它应该具有以下特征:
到目前为止,该功能已基本完成,但存在以下问题:
我需要选择一个取消选中的功能如下:
onCheckDefaults(checked) {
let oldCheck = [...this.state.checkedDefaults]
let difference = checked.filter(x => !oldCheck.includes(x))
let clean = [...checked]
if (difference.length > 0) {
let countParent = difference[0].split("/");
countParent.pop()
let parent = countParent.join("/");
if (oldCheck.length>0) {
for (var j = 0; j < oldCheck.length; j++) {
if (typeof(oldCheck[j])!=="undefined") {
if (oldCheck[j].startsWith(parent + "/")) {
clean = checked.filter((e, i) => {
return e !== oldCheck[j]
})
} else {
clean = checked.filter((e, i) => {
if (e.startsWith(parent + "/")) {
for (var a in difference) {
if (typeof(e)!=="undefined") {
return e !== difference[a]
}
}
}
})
clean=[...oldCheck,clean[0]]
}
}
}
this.setState({
checkedDefaults: clean,
}, () => {
this.addDefaults(clean)
})
} else {
if (checked.length>1) {
checked = checked.filter((e, i) => {
if (e.startsWith(parent + "/")) {
for (var a in difference) {
return e !== difference[a]
}
}
})
}
this.setState({
checkedDefaults: checked,
}, () => {
this.addDefaults(checked)
})
}
} else {
this.setState({
checkedDefaults: checked,
}, () => {
this.addDefaults(checked)
})
}}
谢谢!