search

Home  >  Q&A  >  body text

javascript - How to realize multi-layer nested linkage of tree component with checkbox

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?

滿天的星座滿天的星座2706 days ago657

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-06-26 10:52:15

    http://www.treejs.cn/v3/main....

    Let’s see if this plug-in can satisfy

    reply
    0
  • Cancelreply