本文主要是介绍Cascader 级联选择器 - 选择器最后一级数据为空,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原因:将扁平数据转化为树形数据时,给每个项都添加了 children
export const transList2Tree = (list, rootPid) => {const result = []list.forEach(item => {if (item.pid === rootPid) {const children = transList2Tree(list, item.id)item.children = childrenresult.push(item)}})return result
}
修改代码:
export const transList2Tree = (list, rootPid) => {const result = []list.forEach(item => {if (item.pid === rootPid) {const children = transList2Tree(list, item.id)// 只有 children不为空时,才继续向下找 children 的数据if (children.length > 0) {item.children = children}result.push(item)}})return result
}
这篇关于Cascader 级联选择器 - 选择器最后一级数据为空的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!