<u-cell-group class="list" :border="false"> <u-cell-item :arrow="true" v-for="(child, index2) in child" :key="child.id" @click="navTo('/pages/sys/msg/form')"> <text slot="title" >{{ child.companyName }}</text> </u-cell-item> </u-cell-group> let groups = [...new Set(company2.map(item => item.parentCode))]; let newArr = groups.map(parentCode =>{ let children = company2.filter(item => item.parentCode == parentCode); children.forEach(child => { // 获取当前子项的父项 let parent = company2.find(item => item.parentCode === parentCode); // 将父项的companyName赋值给子项 child.parentName = parent.companyName; }); return children; }); this.child = newArr; console.log(this.child); 如何在text标签里根据夫数组分组显示newArr数组中的子数组的conpanyName
时间: 2024-01-29 15:04:56 浏览: 136
实现div垂直居中的display:table-cell方法示例介绍
你可以使用 `v-for` 循环渲染 `newArr` 数组中的子数组,并在循环内部使用 `u-cell-group` 和 `u-cell-item` 标签来显示 `companyName`。具体代码如下:
```
<template>
<div>
<u-cell-group :border="false" v-for="(children, index1) in child" :key="index1">
<div slot="title">{{ children[0].parentName }}</div>
<u-cell-item v-for="(item, index2) in children" :key="item.id">
<text>{{ item.companyName }}</text>
</u-cell-item>
</u-cell-group>
</div>
</template>
```
这样就能按照父数组分组显示子数组的 `companyName` 了。
阅读全文