Meteor:访问另一个集合,每个块中有一个id

Meteor: Accessing another collection with an id in an #each block

本文关键字:有一个 id 访问 另一个 集合 Meteor      更新时间:2023-09-26

所以我有两个集合,appliers&配置文件,

appliers = {_id,idAppliersProfile}

&

profile = {_id,profilename}

所以我的问题是,如果我为申请者做一个#每个,我如何访问配置文件集合来获得配置文件,而不仅仅是id?谢谢

假设两组文档都发布到客户端,则一个解决方案如下所示:

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);
  }
});
相关文章: