介绍一个vue小应用:table里数组多层嵌套取值。我们来看个例子:
HTML
<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)
网友评论文明上网理性发言 已有0人参与
发表评论: