tree数据如何只要前两级

tree数据如何只要前两级

data: [{

id: 1,

label: '一级 2',

children: [{

id: 3,

label: '二级 2-1',

children: [{

id: 4,

label: '三级 3-1-1'

}, {

id: 5,

label: '三级 3-1-2',

disabled: true

}]

}, {

id: 2,

label: '二级 2-2',

disabled: true,

children: [{

id: 6,

label: '三级 3-2-1'

}, {

id: 7,

label: '三级 3-2-2',

disabled: true

}]

}]

}],


回答:

[{

id: 1,

label: '一级 2',

children: [{

id: 3,

label: '二级 2-1',

children: [{

id: 4,

label: '三级 3-1-1'

}, {

id: 5,

label: '三级 3-1-2',

disabled: true

}]

}, {

id: 2,

label: '二级 2-2',

disabled: true,

children: [{

id: 6,

label: '三级 3-2-1'

}, {

id: 7,

label: '三级 3-2-2',

disabled: true

}]

}]

}].map(v => ({...v, children: v.children.map(o => ({...o, children: []}))}))

以上是 tree数据如何只要前两级 的全部内容, 来源链接: utcz.com/p/935936.html

回到顶部