iview树形组件后台数据转为对应treeData的字段

参考地址:https://segmentfault.com/q/1010000012064522/a-1020000012149722

 function getTree(tree = []) {
        let arr = [];
        if (!!tree && tree.length !== 0) {
            tree.forEach(item => {
                let obj = {};
                obj.title = item.name;
                obj.attr = item.attr; // 其他你想要添加的属性
                obj.expand = false;
                obj.selected = false;
                obj.children = getTree(item.childrenFilenames); // 递归调用
                arr.push(obj);
            });
        }
        return arr;
    }

你可能感兴趣的:(iview树形组件后台数据转为对应treeData的字段)