vue table表格里面数组多层嵌套取值
我现在是在表格里拿到级联选择器的多选的id,然后要根据这个id来匹配一个嵌套了三层的数组的第三层id,来拿名字渲染
表格部分
<tr style="height: 44px;line-height: 44px;">
? ? ? ? ? ? ? ? <td style="border: 1px solid #ddd;">提醒给</td>
? ? ? ? ? ? ? ? <td style="border: 1px solid #ddd;">
? ? ? ? ? ? ? ? ? <!-- {{editForm.uids.toString().split(',')}} -->
? ? ? ? ? ? ? ? ? <span v-for="item in editForm.uids.toString().split(',')" :key="item.id">
? ? ? ? ? ? ? ? ? ? <!-- <p>{{dataHandle(editForm.uids)}}</p> -->
? ? ? ? ? ? ? ? ? ? <p>{{dataHandle(item)}}</p>
? ? ? ? ? ? ? ? ? </span>
? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? </tr>
``
methods里面定义方法
?// 提醒给点击事件
dataHandle(item) {
? ?let ary = []
?let name = ''
? let result = getUserName(this.options4)
? result.forEach(v2 => {
? ? if (item == v2.id) {
? ? ? name = v2.corp_name
? ? }
? })
? return name
??
? function getUserName(item) {
? ? item.forEach(v1 => {
? ? ? if (v1.children) return getUserName(v1.children)
? ? ? else {
? ? ? ? ary.push(v1)
? ? ? }
? ? })
? ? return ary
? }
},
vue 多层数组嵌套循环,动态取值匹配
tableData:[], //存储数组
arrTarName:[] //结果数组
this.tableData.push({
siteName:i.siteName,
tabdata:result.data
});
//循环+判断取值
for (let k = 0; k < result.data.length; k++) {
if (this.arrTarName.length == 0) {
this.arrTarName.push({
indexName: result.data[k].indexName,
polTracesouCount: result.data[k].polTracesouCount
})
} else {
let isExist = false;
for (let l = 0; l < this.arrTarName.length; l++) {
if (this.arrTarName[l].indexName == result.data[k].indexName) {
isExist = true;
this.arrTarName[l].polTracesouCount = this.arrTarName[l].polTracesouCount + result.data[k].polTracesouCount;
break;
}
}
if (!isExist) {
this.arrTarName.push({
indexName: result.data[k].indexName,
polTracesouCount: result.data[k].polTracesouCount
})
}
}
}
console.log(this.arrTarName)
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
查看更多关于vue实现table表格里面数组多层嵌套取值的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did123461