- requirements: recursively unchecked objects
- expectation: the object of checked: false cannot be selected, for example, in the following data (watermelon, pudding, tasteless)
- data
[
{
title: "parent 1",
expand: true,
checked: false,
children: [
{
title: "parent 1-1",
expand: true,
checked: false,
children: [
{
checked: false,
title: ""
},
{
checked: false,
title: "leaf 1-1-2"
}
]
},
{
title: "parent 1-2",
checked: false,
expand: true,
children: [
{
checked: false,
title: "leaf 1-2-1"
},
{
checked: false,
title: "leaf 1-2-1"
}
]
}
]
},
{
title: "parent 11",
checked: false,
expand: true,
children: [
{
title: "parent 11-1",
checked: false,
expand: true,
children: [
{
checked: false,
title: "leaf 11-1-1"
},
{
checked: false,
title: "leaf 11-1-2"
}
]
},
{
title: "adfasdfas",
checked: false,
expand: true,
children: [
{
checked: false,
title: ""
},
{
checked: false,
title: ""
}
]
}
]
}
]
implementation method:
function findTarget(source, targetName) {
if (source && source.length) {
for (let item of source) {
if (item.checked === targetName) {
console.log(item.title);
} else if (item.children && item.children.length) {
findTarget(item.children, targetName);
}
}
}
}
findTarget(this.data2, false);
for (let i = 0; i < this.data2.length; iPP) {
findTarget(this.data2[i], false);
}
}
problem: unable to achieve the desired effect