【问题标题】:Why is my select not being populated with my MongoDB Collection?为什么我的选择没有填充我的 MongoDB 集合?
【发布时间】:2015-09-03 03:26:17
【问题描述】:

在我的 Meteor 应用中,我正在发布:

ForeignVisaTypes = new Mongo.Collection("foreignVisaTypes");

if (Meteor.isServer) {

    Meteor.publish("foreignVisaTypes", function () {
      return ForeignVisaTypes.find();
    });
}

...并订阅:

if (Meteor.isClient) {

  Meteor.subscribe("foreignVisaTypes");
  . . .
}

...一个集合,其中 填充了值。

但是,这种填充选择的尝试失败了:

<select name="selvisatype" id="selvisatype" title="Please select a visa type">
    {{#each foreignVisaTypes}}
      <option value={{value}}>{{display}}</option>
    {{/each}}
</select>

为什么会失败?

【问题讨论】:

  • 你在哪里定义 foreignVisaTypes 助手?

标签: mongodb meteor html-select


【解决方案1】:

订阅一个集合是不够的。它不能直接在空格键中作为助手使用。所以你仍然需要定义一个 helper 来公开它。

只需将此添加到您的客户端代码中,一切就应该开始工作了(将 myTemplate 替换为您的模板名称):

Template.myTemplate.helpers({
    foreignVisaTypes: function() {
        return ForeignVisaTypes.find();
    }
});

【讨论】:

    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 2015-12-02
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多