在我的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>
为什么会失败?
答案 0 :(得分:1)
订阅收藏品还不够。它不会作为助手直接在空格键中使用。所以你仍然需要定义一个帮助器来暴露它。
只需将此添加到您的客户端代码中即可开始工作(将myTemplate替换为模板名称):
Template.myTemplate.helpers({
foreignVisaTypes: function() {
return ForeignVisaTypes.find();
}
});