美文网首页
ivew的tree用法

ivew的tree用法

作者: 谁还不是个小仙女似的 | 来源:发表于2019-03-28 17:28 被阅读0次

    使用常规的方法传值

    // recursion .js 转换树
    const recursion = {
      // 转换树结构并将需要的值存进树中
      // 存值为:除了树结构必须的值外,我需要发送给后台的值 (code)
      convertTree: function (tree, map) {
        const result = [];
        tree.forEach((item) => {
          // 读取 map 的键值映射
          let expand = !!item.children;
          let checked = false;
          let title = item[ map.title ];
          let code = item[ map.code ];
          let children = item[ map.children ];
          // 如果有子节点,递归
          if (children) {
            children = this.convertTree(children, map);
          }
          result.push({ expand, checked, code, title, children });
        })
        return result;
      },
    }
    
    export default recursion
    
    // vue文件中引入
    import recursion  from './recursion '
    
    // 后台返回的字段
     var data = [
        {"id":"0E8A7BEC-5D6C-4626-9C66-47C97A9ACC84","parentId":"00000000-0000-0000-0000-000000000000","isFinal":0,"treeLevel":1,"children":[
            {"id":"0E8A7BEC-5D6C-4626-9C66-47C97A9ACC845","parentId":"00000000-0000-0000-0000-000000000001","isFinal":1,"treeLevel":1,"children":null,"name":"天凝镇人民政府1","code":"11","remark":null,"isForbidden":0},
            {"id":"0E8A7BEC-5D6C-4626-9C66-47C97A9ACC846","parentId":"00000000-0000-0000-0000-000000000002","isFinal":1,"treeLevel":1,"children":null,"name":"天凝镇人民政府2","code":"12","remark":null,"isForbidden":0}
          ]
          ,"name":"天凝镇人民政府","code":"1","remark":null,"isForbidden":0}
      ]
    const map = {
      title: 'name',
      children: 'finClassList',
      code: 'code'
    }
    this.typeTree = recursion.convertTree(data, map)
    

    相关文章

      网友评论

          本文标题:ivew的tree用法

          本文链接:https://www.haomeiwen.com/subject/uasqbqtx.html