【树型结构-vue】

【树型结构-vue】,第1张

表格树型结构的处理--树型处理工具函数

/***
 *   数组树形结构 转数型结构
 * */
export function ArrTree(data) {
  var nwearr = data;
  let result = [];
  if (!Array.isArray(data)) {
    return result;
  }
  data.forEach(item => {
    delete item.children;
  });
  let map = {};
  data.forEach(item => {
    map[item.id] = item;
  });
  data.forEach(item => {
    let parent = map[item.pid];

    if (parent) {
          if (item.pid != 0) {
            let fffffff = nwearr.find(cc => {
              return cc.id == item.pid;
            });
            if (fffffff != undefined) {
              (parent.children || (parent.children = [])).push(item);
            }
          } else {
            (parent.children || (parent.children = [])).push(item);
          }
    } else {
      if (item.pid != 0) {
        let  fffffff = nwearr.find(cc => {
          return cc.id == item.pid;
        });
        if (fffffff != undefined) {
          result.push(item);
        }
      } else {
        result.push(item);
      }
    }
  });
  return result;
}

页面

```



toggleRowExpansion(isExpansion){
  this.toggleRowExpansion_forAll(this.crud.data,isExpansion);
},
toggleRowExpansion_forAll(data,isExpansion){
  data.forEach(item=>{
    this.$refs.table.toggleRowExpansion(item,isExpansion);
    if(item.children != undefined && item.children != null){
      this.toggleRowExpansion_forAll(item.children,isExpansion);
    }
  })
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/946609.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-18
下一篇2022-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存