Handling of repeated child nodes of element tree control

Record a pit that was stepped on using the element tree control


Requirements : What we need to do this time is the requirement of role permission configuration. We need to use the element tree control to assign corresponding navigation menus to the corresponding roles, as shown in the figure below

Problem : The main problem when writing is that when only one child component is selected and the parent component is not selected, two pieces of data will be printed out, one complete parent node contains child node data, and the other simply only has child node data. At this time, you need to pass the checked data information to the background.
insert image description here
Data is the clicked data, and checked is the checked data.
After writing, the printed data will have a parent component that contains subcomponents, and a single subcomponent. In short, it will Very messy
insert image description here
, there will be a bug effect like this, and there are other effects of menu
insert image description here
confusion . For nodes, it is necessary to cycle through the sub-nodes and then de-duplicate all the checked menu data. If there is the same, only the data of a single sub-node is kept
insert image description here
insert image description here
. For a long time, I tried a lot but failed to achieve it. In fact, I thought about it at the beginning, but I didn’t write it well. The main reason is that the subscript of the obtained collection is wrong, so I have been unable to delete the duplicate data correctly. Then I saw Baidu search The corresponding subscript can be obtained through the id in this way. I learned it, I learned it, and I will share it with you

var index = checked.map(function (item) {
    
     return item.id; }).indexOf(item.id);

Guess you like

Origin blog.csdn.net/yangsi0706/article/details/116937671
Recommended