I am currently making a tree component with a checkbox. My rendering idea is to recurse from the parent class to the child class. If there is a children attribute, let children call itself. The code is as follows
data = [{
label: 111,
children: [{
label: 222,
}]
}, {
label: 333
}]
translate = (content, key, first) => {
content.forEach((i, index) => {
i.key = key + (first ? '' : '-') + (index + 1);
i.checked = this.defaultCheckedKey.toString().indexOf(i.key) > -1;
i.expanded = this.defaultExpandedKey.toString().indexOf(i.key) > -1;
i.nodeLevel = i.key.split('-').length;
i.checked && selectedKeys.push(i.key);
if (i.children && i.children.length > 0) {
this.translate(i.children, i.key, false);
}
})
};
ngOnInit() {
this.translate(this.data, '', true);
}
Now we need to do checkbox selection linkage. If we recurse from the parent class to the child class, n-1 recursions are needed, which seems to affect the performance. Can anyone give me a solution for checkbox multi-layer nested linkage?