/**
* list? 初始數(shù)組
*? 父級的id與子級的parentId對應(yīng),是api必須返回的數(shù)據(jù)
* ‘-1‘? ? 根據(jù)api返回的最上面那級的parentId進(jìn)行判斷
*/
buildTree(list) {
? lettemp = {}
? lettree = []
? for (leti in list) {
? ? temp[list[i].id] = list[i]
}
? for (leti in temp) {
? ? if (temp[i].parentId !== '-1') {
? ? ? if (!temp[temp[i].parentId].children) {
? ? ? ? temp[temp[i].parentId].children = []
}
? ? ? temp[temp[i].parentId].children.push(temp[i])
? ? } else {
? ? ? tree.push(temp[i])
}
}
? return tree
}