像是闭包 但是不知道怎么写?-灵析社区

抠香糖

穿梭框功能 arr1是穿梭框左侧的全部数据 大致意思是 最后一层的title全部选中就把上一层的title名称放入数组中 如果子children没全部选中则把选中的title放入数组中 arr1 = [ { title:'全部', children:[ { title:'小明0.1', children:[ { title:'小明0.1.1', children:[ { title:'小明0.1.1.1', children: [] } ] }, { title:'小明0.1.2', children:[ { title:'小明0.1.2.1', children: [] } ] }, ] }, { title:'小明0.2', children:[ { title:'小明0.2.1', }, { title:'小明0.2.2', }, { title:'小明0.2.2', } ] } ] } ]

阅读量:315

点赞量:17

问AI
这听上去就是一个递归,然后修改自己的状态。 然后我看了一下 ai 的答案,不忍直视。 这里遍历的话可以考虑深度优先遍历 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241231/643468c190f179da2a589325a4ba3a2c.png) 看上去遍历没问题 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241231/d83e50579ed1a998e411fea4690b9280.png) 遍历的时候做两个状态判断一下就可以了 *** 但是我没有从上往下覆盖,所以会出现这种情况 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241231/04e77e5d7911dee8822667b7af8f3fb0.png) 到此就完成了你所需要的功能,不过这个需求一般 tree 组件都支持 *** 可以在计算的时候,用计算值计算,可以直接向上继承 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241231/7de673280bea11881496a31c5bc17f54.png)