数据格式
后端返回数据
由于后端返回来的只有最后一级的key,所以我们需要写一个递归来拿到最后一级key和它父级key的数组
getParentsById(list, key) {
for (let i in list) {
if (list[i].key == key) {
return [list[i].key]
}
if (list[i].children && list[i].children.length) {
let valList = this.getParentsById(list[i].children, key)
if (valList !== undefined) {
valList.unshift(list[i].key)
return valList
}
}
}
},
调用
this.editFormFields.producttype = this.getParentsById(list,key)