//重新向新的数组里面塞值 function renderListValue(arr, newarr) { for (let i = 0; i < arr.length; i++) { let obj = {} if (arr[i].leaf == true) { obj.budgetAmount = arr[i].value obj.typeId = arr[i].key newarr.push(obj) } if (arr[i].children && arr[i].children.length > 0) { renderListValue(arr[i].children, newarr) } } return newarr } //递归赋值 function renderCode(arr, code, text) { for (let i = 0; i < arr.length; i++) { if (arr[i].code == code) { arr[i].value = text } if (arr[i].children && arr[i].children.length > 0) { renderCode(arr[i].children, code, text) } } return arr } //根据id或者key取到父级 function findParent(data, code) { let result = null function setParent(data) { data.children.forEach((item, index) => { item.index = index item.parent = data if (item.code === code) { result = item } if (item.children && item.children.length) { setParent(item) } }) } data.forEach((item, index) => { item.index = index setParent(item) }) return result ? result.parent : null }