我刚接触Vue.js,正在try 合并具有相同值的行,但我的表没有正确显示.我被困住了,有人能给我建议吗?

async getNetworks(audId) {
    try
    {
        const response = await this.axios.get("/s/teams/network-groupss?audId=" + audId);
            
        if (!this.networkGroups[audId])
        {
            this.$set(this.networkGroups, audId, {});
            this.$set(this.networkGroups[audId], 'isExpanded', false);
        }
            
        this.$set(this.networkGroups[audId], 'data', response.data ? response.data.data : []);
    }
        catch (error)
        {         
                console.log(error.message);
            }
        
    
}
<tbody class="network_Group">
    <tr
    v-for="(networkGroup) in networkGroups[team.id].data"
    :key="networkGroup.id"
    :class="{ odd2: index % 2 !== 0 }">
        <td
            class="text-center data-column first_row">
            <span> {{ networkGroup.source }} </span>
        </td>
        <td class="text-center data-column">
            <span> {{ networkGroup.name }} </span>
        </td>
        <td class="text-nowrap text-left breakAll">
            <span> {{ networkGroup.accountId }}</span>
        </td>
        <td class="text-center data-column">
            <span> {{ networkGroup.size }} </span>
        </td>
    </tr>
</tbody>

这是我的桌子:

推荐答案

try 以下代码片段:

const app = Vue.createApp({
  data() {
    return {
      networkGroups: [{id: 1, source: "group A", name: "Aples", accountId: "1237", size: 9}, {id: 2, source: "group B", name: "Oranges", accountId: "0293", size: 7}, {id: 3, source: "group A", name: "Carrots", accountId: "3849", size: 1}, {id: 4, source: "group B", name: "Onions", accountId: "8172", size: 3}, {id: 5, source: "group B", name: "Mangos", accountId: "2742", size: 10}],
    };
  },
  computed: {
    groups() {
      const gr = []
      this.networkGroups.forEach(g => {
        if (!gr.includes(g.source)) gr.push(g.source)
      })
      return gr
    },
  },
  methods: {
    net(group) {
      return this.networkGroups.filter(n => n.source === group)
    }
  },
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
<table>
  <tbody class="network_Group">
    <tr v-for="(gr, idx) in groups" :key="idx">
      <td class="text-center data-column first_row">
        <span> {{ gr }} </span>
      </td>
      <td>
        <table>
          <tbody class="network_Group">
            <tr
              v-for="(networkGroup) in net(gr)"
              :key="networkGroup.id"
              :class="{ odd2: index % 2 !== 0 }">
              <td class="text-center data-column">
                  <span> {{ networkGroup.name }} </span>
              </td>
              <td class="text-nowrap text-left breakAll">
                  <span> {{ networkGroup.accountId }}</span>
              </td>
              <td class="text-center data-column">
                  <span> {{ networkGroup.size }} </span>
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>
</div>

Javascript相关问答推荐

使用JavaScript/PHP将二维码保存为服务器端的图像

如何使用JavaScript对切换的声音设置音量

React:如何将表格收件箱正确渲染为表格主体内的组件?

React状态变量在使用++前置更新时引发错误

在JS中获取名字和姓氏的首字母

是什么原因导致此Angular 16应用程序中类型错误时属性结果不存在?

Vue:ref不会创建react 性属性

当在select中 Select 选项时,我必须禁用不匹配的 Select

窗口.getComputedStyle()在MutationObserver中不起作用

无法在nextjs应用程序中通过id从mongoDB删除'

D3 Scale在v6中工作,但在v7中不工作

在286之后恢复轮询

如何从Intl.DateTimeFormat中仅获取时区名称?

映射类型定义,其中值对应于键

在使用REACT更改了CSS类之后,无法更改CSS样式

传递方法VS泛型对象VS事件特定对象

使用Document.Evaluate() Select 一个包含撇号的HTML元素

Next.js中的服务器端组件列表筛选

无法读取未定义的属性(正在读取合并)-react RTK

通过跳过某些元素的对象进行映射