递归 js,递归改所有node里面属性名字

1.递归拿出不是叶子结点的id数组

getPriv(this.roleId).then((response) => { const privData = https://www.it610.com/article/this.privData var a = [] var forfn = function (list) { for (var i = 0; i < list.length; i++) { if (list[i].children) { a.push(list[i].id) forfn(list[i].children) } } } forfn(privData) //比对a和b this.privIds为在b数组中去除a数组包含的元素后形成的数组 var b = response.data let RemoveSame = [...new Set([...a, ...b])] let SamePart = a.filter((item) => b.includes(item)) let Difference = RemoveSame.filter( (item) => !SamePart.includes(item) ) this.privIds = Difference // this.$refs.menu.setCheckedNodes(response.data) })

【递归 js,递归改所有node里面属性名字】2.递归改所有node里面属性名字
getTree().then((response) => { this.menuOptions = [] //data为需要修改的tree,这里主要是为antd design 里面select规范数据const ass = (data) => { let item = [] data.map((list, i) => { let newData = https://www.it610.com/article/{} newData.title = list.label newData.id = list.id newData.parentId = list.parentId newData.children = list.children ? ass(children) : [] //如果还有子集,就再次调用自己 item.push(newData) }) return item } var rda = ass(response.data)this.menuOptions = rda })

    推荐阅读