Meteor:访问#each块中具有id的另一个集合

时间:2016-04-19 22:37:58

标签: javascript meteor each

所以我有两个系列,appliers&型材,

appliers = {_id,idAppliersProfile}

&安培;

profile = {_id,profilename}

所以我的问题是,如果我为应用程序执行#each,如何访问配置文件集合以获取配置文件而不仅仅是id? 感谢。

1 个答案:

答案 0 :(得分:1)

假设两组文档都发布到客户端,一个解决方案看起来像这样:

<强> HTML

<template name="myTemplate">
  {{#each appliers}}
    {{#with getProfile idAppliersProfile}}
      <div>{{profilename}}</div>
    {{/with}}
  {{/each}}
</template>

<强> JS

Template.myTemplate.helpers({
  appliers: function () {
    return appliers.find();
  },

  getProfile: function (id) {
    return profile.findOne(id);
  }
});
相关问题