我正在使用Meteor 1.0
我有以下代码:
/lib/collections.js
Members = new Mongo.Collection('members');
/lib/router.js
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
waitOn: function() { return Meteor.subscribe('members'); }
});
Router.route('/', {name: 'menu'});
Router.route('/member/new/', {name: 'memberNew'});
Router.route('/member/renew/', {name: 'memberRenewal'});
/server/publications.js
Meteor.publish('members', function() {
console.log("Publishing....");
return Members.find();
});
/client/templates/memberList.js
Template.membersList.helpers({
listMembers: function() {
return members.find().fetch(); >>>>>> Error line
}
});
我收到以下错误:
Exception in template helper: ReferenceError: members is not defined
at Object.Template.membersList.helpers.listMembers
(http://meteorvb.dhcp.meraka.csir.co.za:3000/client/templates/membersList.js?
如果我将/client/templates/memberList.js更改为
,我已删除了自动发布位Template.membersList.helpers({
listMembers: function() {
return Members.find().fetch();
}
});
一切正常。
有人可以帮助我吗?
答案 0 :(得分:1)
我认为这只是一个错字,你使用小写m而不是大写M代表会员。
Template.membersList.helpers({
listMembers: function() {
return Members.find().fetch(); >>>>>> Error line
}
});
变量区分大小写,因为成员集合已分配给“成员”,您需要在其他地方将其称为“成员”。
Members = new Mongo.Collection('members');