当前位置:网站首页>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;
},
边栏推荐
猜你喜欢
LeetCode 729. 我的日程安排表 I
Postman核心功能解析-参数化和测试报告
ESP32 ESP-IDF看门狗TWDT
数据库隔离级别
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
Digital triangle model acwing 1015 Picking flowers
在uni-app中使用腾讯视频插件播放视频
JWT-JSON WEB TOKEN
D - How Many Answers Are Wrong
Career advancement Guide: recommended books for people in big factories
随机推荐
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
PAT(乙级)2022年夏季考试
leaflet 地图
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
(中)苹果有开源,但又怎样呢?
Play video with Tencent video plug-in in uni app
二维码的前世今生 与 六大测试点梳理
JWT-JSON WEB TOKEN
Simulation volume leetcode [general] 1109 Flight reservation statistics
Summary of anomaly detection methods
JWT-JSON WEB TOKEN
Win10 cannot operate (delete, cut) files
sourceInsight中文乱码
Web界面元素的测试
Past and present lives of QR code and sorting out six test points
Hypothesis testing learning notes
Testing and debugging of multithreaded applications
Redis core technology and basic architecture of actual combat: what does a key value database contain?
GTSAM中李群的運用
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete