tree 向下查找 (刪除整條tree)

需求:經過點擊獲取須要刪除的id(即獲取到整條信息),若是該條數據沒有子集,經過id刪除便可,若是有子集,則該數據下全部的子集都須要刪 node

刪除後頁面的數據更新在 下一篇 講解ios

 1 const id ='123';  //刪除節點的id(點擊獲取到的id);
 2 const localTree = [...];   //獲取到須要被刪除的樹(不包括id對應的節點,能夠稱之爲被刪除的根節點)
 3 let ids = [];  //多條刪除id集合
 4 ids.push(id);
 5 if (localTree) {
 6    const newTeams = function (data, parentId) {
 7          for (let i = 0; i < data.length; i++) {
 8              const node = data[i];
 9              ids.push(node.id);    //每循環一次就將獲取到的id添加到id集合中
10              const children = node.children;
11              if (children.length) {
12                  newTeams(children, children[0].id);
13              }
14          }
15     }
16     newTeams(localTree, id);   //執行方法
17 }
18 
19 //注:此方法主要的獲取須要被刪除的id集合 20 //for of 循環刪除 ,這裏是saga進行刪除,刪除多條時,須要for of 循環刪除
21 for (let i of ids) {
22     yield axios.delete('/api/AssetClasses/' + i);
23};
相關文章
相關標籤/搜索