1. 递归拿出不是叶子结点的 id 数组
getPriv(this.roleId).then((response) => {
const privData = 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)
})
2. 递归改所有 node 外面属性名字
getTree().then((response) => {this.menuOptions = []
//data 为须要批改的 tree,这里次要是为 antd design 外面 select 标准数据
const ass = (data) => {let item = []
data.map((list, i) => {let newData = {}
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
})