时长60min,全是写题,
1、树的结构中过滤出要找的节点
tree = [
{ name: 'A' },
{
name: 'B', children: [
{ name: 'A' },
{name:'AA',children:[{name:'AAA'}]}
]
},
{name:'C'}
]
// 1.假设我输入的str为A, 则过滤后返回的结果为
[
{ name: 'A' },
{name:'B',children:[{name:'A'}]}
]
//2.假设我输入的str为AA,则过滤后返回的结果为
[
{
name: 'B', children: [
{name:'AA',children:[{name:'AAA'}]}
]}
]
//3.假设我输入的str为B,则过滤后返回的结果为
[
{
name: 'B', children: [
{ name: 'A' },
{name:'AA',children:[{name:'AAA'}]}
]}
]
function clear(tree,filterName){
if(!tree) return [];
let result = [];
tree.map((item) => {
let it = {...item};
if(it.name == filterName){
result.push(it);
}else{
let obj = clear(it.children,filterName);
if(obj.length > 0){
it.children = obj;
result.push(it);
}
}
})
return result;
}
console.log(clear(tree,"A"))
2、列表转树
3、css,两栏布局
4、vue组件写一个todolist,渲染组件,父子组件之间传值