you need to get a collection of all the id of isCheck = true
list: [{
id: "1",
isCheck: false,
children: [{
id: "1-1",
isCheck: false,
children: null
}, {
id: "1-2",
isCheck: true,
children: null
}]
}, {
id: "2",
isCheck: false,
children: [{
id: "2-1",
isCheck: true,
children: null
}]
}, {
id: "3",
isCheck: true,
children: null
}]
think of using recursive algorithm to flatten and degrade the array, but the data obtained is not right. I hope to get the data
.["1-2", "2-1", "3"]
steamroller: function (arr) {
let newArr = []
let flat = function (item) {
for (var i = 0; i < item.length; iPP) {
if (Array.isArray(item[i].children)) {
flat(item[i])
} else {
newArr.push(item[i])
}
}
}
flat(arr)
return newArr
}
ask for help!