Vue 和元素组件

Vue and Element Component

我有一个复杂的对象,为简洁起见,对象的结构如下:

{
     Sample: [{
      Model: {
          Id: "1"
      },

      Collection: [{
          Id: "1"
      }]    
     }]
}

数据 table 可以很好地呈现模型数据。但是,当尝试访问集合时,table 不输出数据。

<template>
     <el-table :data="Sample" highlight-current-row :row-class-name="tableRow" stripe :default-sort="{ prop: 'Sample.Id, order: 'descending'}">
          <el-table-column type="expand">
               <el-row :gutter="20" v-for="property in Collection">
                    <el-col :span="24"><div>Id: {{ property.Id }}</div></el-col>
               </el-row>
          </el-table-column>
          <el-table-column prop="Model.Id" label="Id" width="300"></el-table-column>
     </el-table>
</template>

绑定到 table 的数据是否忽略循环?我可以在绑定期间作为道具访问,数据正在发送过来,但是当添加循环时,数据没有输出。

Element-io Vue

我知道为什么循环不起作用,因为 CollectionSample 中。你的数据结构是一个Sample数组,它包含一个对象。

因此,您可以将代码修改为:

v-for="(property,index) in Sample[0].Collection"