Home > Blockchain >  adding children to tree view node from an array issue
adding children to tree view node from an array issue

Time:01-06

I am trying to add children to my treeview node. But its getting duplicate error.

                    const persons = [];
                    for (let i = 0; i < data.length; i  ) {
                      persons.push({ 
                          value: data[i].id, 
                          label: data[i].name,
                          
                          children: [
                          {  value: data[0].children[0].id,
                             label:data[0].children[0].name 
                            }
                          ]
                       }) 
                      } 
                      
                      this.setState({ persons });

error message is CheckboxTreeError: Duplicate value '01-C11' detected. All node values must be unique.

If I remove children then it works well.

CodePudding user response:

Don't you want the children data also to get from index instead of the first element?

In here?

children: [{  
    // Shouldn't the first 0 here be i ?
    value: data[0].children[0].id,
    label: data[0].children[0].name 
}]
  • Related