当前位置:网站首页>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;
},
边栏推荐
猜你喜欢
随机推荐
联合索引的左匹配原则
Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
Web界面元素的测试
Left matching principle of joint index
[postman] the monitors monitoring API can run periodically
数据库隔离级别
[postman] dynamic variable (also known as mock function)
Idea new UI usage
数据库-当前读与快照读
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
Properties file
通过修改style设置打印页样式
Digital triangle model acwing 1015 Picking flowers
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
JMeter做接口测试,如何提取登录Cookie
自定义指定路由上的Gateway过滤器工厂
Play video with Tencent video plug-in in uni app
oscp raven2靶机渗透过程
E - food chain
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误









