简体   繁体   English

流星:遍历对象内部的对象数组

[英]Meteor : Iterate through array of Objects inside an Object

I'm currently trying to iterate through an array of Objects inside an Object. 我目前正在尝试遍历对象内的对象数组。 I have my Collection "Proposals", and this is the corresponding Schema : 我有我的收藏集“ Proposals”,这是相应的Schema:

Schemas.ProposalsSchema = new SimpleSchema({
  'content': {
    type: String,
    max: 140
  },
  'parties': {
    type: [Object],
    autoform : {
      type: "select-multiple"
    }
  },
  'parties.$._id': {
    type: Object,
    optional: true
  },
  'parties.$._id._str': {
    type: String
  },
  'parties.$.name': {
    type: String
  }
});

I would like to iterate through the array of parties inside one of my template. 我想遍历我的模板之一内的一系列聚会。 I tried this : 我尝试了这个:

{{#each proposals}}
    <p>{{content}}</p>
    <p>{{#each parties}} {{this.name}} {{/each}}</p>
{{/each}}

The content is displayed, but not the name of the different parties. 显示内容,但不显示不同方的名称。 Here's my template helper : 这是我的模板助手:

Template.proposalsIndex.helpers({
  proposals: () => Proposals.find().fetch()
});

Do you know what do i do wrong? 你知道我做错了什么吗?

Thank you in advance. 先感谢您。

The code you posted looks ok. 您发布的代码看起来还可以。

Things you need to check are: 您需要检查的内容是:

  1. Is the "parties" field populated in a database? 数据库中是否填充了“ parties”字段? (you can run Proposals.find().fetch() in a meteor shell to check it). (您可以在meteor shell运行Proposals.find().fetch()进行检查)。

    If not, find out why it is not populated. 如果不是,请找出为什么不填充它。

  2. Is the "parties" field published to client? “当事人”字段是否发布给客户? (you can run Proposals.find().fetch() in a browser console and see the results). (您可以在浏览器控制台中运行Proposals.find().fetch()并查看结果)。

    If not, check your publication. 如果没有,请检查您的出版物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM