遍历tree

1.解决方法

filterData (arr) {
            var newArr = []
            arr.map((item) => {
                var childrenArr
                if (item.children !== null && item.children !== []) {
                    childrenArr = this.filterData(item.children)
                } else {
                    childrenArr = []
                }
                newArr.push({
                    title: item.menuTitle,
                    checked: item.selected,
                    children: childrenArr,
                    expand: item.expand,
                    menuId: item.menuId,
                    menuPid: item.menuPid
                })
            })
            return newArr
        },

 

 

2.解决方法

getTree (tree = []) { // 过滤接口中的数据变为tree所用数据
            let arr = []
            if (!!tree && tree.length !== 0) {
                tree.forEach(item => {
                    let obj = {}
                    obj = {...item}
                    obj.title = item.orgName
                    obj.expand = false
                    obj.children = this.getTree(item.subOrgs)
                    arr.push(obj)
                })
            }
            return arr
        },

 

posted @ 2019-06-14 09:17  前端王者(法师)  阅读(1170)  评论(0编辑  收藏  举报