当前位置:网站首页>Convert the array selected by El tree into an array object
Convert the array selected by El tree into an array object
2022-07-06 06:20:00 【Don't sleep I】
problem :
el-tree Render according to the structure of the array object , When we check the desired data, only an array will be generated
Desired effect :
Get the selected data ( Array ), According to the father A Inferior son a Structure , Perform data structure conversion corresponding to parent-child level
My data structure :
Post code : Direct copy , Change the variable name to use
<el-tree
:data="collectionListData"
show-checkbox
node-key="id"
@check="checkFn"
ref="tree"
:props="defaultProps">
</el-tree>
// In the following code devices Is my child array data , Remember to change
checkFn(data, node) {
let nodearr = [];
if (!node.halfCheckedKeys.length) {
node.checkedNodes.forEach((item) => {
if (item.devices) {
nodearr.push(item);
}
});
} else {
let nodeCheckedNodes = node.checkedNodes;
let nodeHalfCheckedNodes = node.halfCheckedNodes;
nodeHalfCheckedNodes.forEach((item) => {
let assign = Object.assign({
}, item);
assign.devices = [];
let childrenLength = item.devices;
for (let i = 0; i < nodeCheckedNodes.length; i++) {
if (nodeCheckedNodes[i].devices) {
nodearr.push(nodeCheckedNodes[i]);
} else {
for (let j = 0; j < childrenLength.length; j++) {
if (nodeCheckedNodes[i].id != childrenLength[j].id) {
continue;
} else {
assign.devices.push(childrenLength[j]);
}
}
}
}
nodearr.push(assign);
});
}
this.nodeList = nodearr;
},
边栏推荐
猜你喜欢
【Postman】测试(Tests)脚本编写和断言详解
Manhattan distance sum - print diamond
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
Manhattan distance and Manhattan rectangle - print back font matrix
全链路压测:构建三大模型
[eolink] PC client installation
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
Customize the gateway filter factory on the specified route
Delete the variables added to watch1 in keil MDK
Basic knowledge of error
随机推荐
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Leaflet map
Reading notes of effective managers
LeetCode 732. 我的日程安排表 III
Testing of web interface elements
F - True Liars (种类并查集+DP)
JDBC Requset 对应内容及功能介绍
测试周期被压缩?教你9个方法去应对
调用链监控Zipkin、sleuth搭建与整合
「 WEB测试工程师 」岗位一面总结
Simulation volume leetcode [general] 1314 Matrix area and
Delete the variables added to watch1 in keil MDK
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
Web界面元素的测试
模拟卷Leetcode【普通】1314. 矩阵区域和
模拟卷Leetcode【普通】1405. 最长快乐字符串
二维码的前世今生 与 六大测试点梳理
Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
Significance of unit testing
SourceInsight Chinese garbled