【发布时间】:2014-02-21 04:25:10
【问题描述】:
这就是我在 app 文件夹根目录下的 router.js 文件中的内容
this.route('pollyShow', {
path: '/polly/:_id',
template: 'polly_show',
notFoundTemplate: 'notFound',
waitOn : function () {
return Meteor.subscribe('polls_all');
},
before: function () {
Meteor.subscribe('polls_all');
var Polls = new Meteor.Collection('polls_all');
console.log(Polls);
var id = this.params._id;
var poll = Polls.findOne({_id: id});
console.log(poll);
},
});
我已经在我的 server/server.js 文件中找到了这个
Meteor.publish('polls_all', function () {
return Polls.find({});
});
我的 console.log 中出现以下错误
console.log(Polls) 返回以下Meteor.Collection {_makeNewID: function, _transform: null, _connection: Connection, _collection: LocalCollection, _name: "polls_all"…}
这显然不是我所期望的。
然后console.log(poll) 按预期返回undefined,因为console.log(Polls) 返回的东西完全出乎意料。
最后我得到以下错误。
Exception from Deps recompute: Error: There is already a collection named 'polls_all'
at new Meteor.Collection (http://localhost:3000/packages/mongo-livedata.js?32cb8e7b8b1a4ecda94a731b3a18e434e3067a5f:263:13)
at route.before (http://localhost:3000/router.js?f11d1e915689f0ca34e03814eb5acc76c7d2d798:15:16)
at IronRouteController.runHooks (http://localhost:3000/packages/iron-router.js?7a9e077ee92fd60193e5d33532c9c2406c28cb5b:649:12)
at Utils.extend.run (http://localhost:3000/packages/iron-router.js?7a9e077ee92fd60193e5d33532c9c2406c28cb5b:2024:10)
at null._func (http://localhost:3000/packages/iron-router.js?7a9e077ee92fd60193e5d33532c9c2406c28cb5b:1484:22)
at _.extend._compute (http://localhost:3000/packages/deps.js?eba25ec453bb70e5ae5c2c54192d21e0e4d82780:183:12)
at _.extend._recompute (http://localhost:3000/packages/deps.js?eba25ec453bb70e5ae5c2c54192d21e0e4d82780:196:14)
at _.extend.flush (http://localhost:3000/packages/deps.js?eba25ec453bb70e5ae5c2c54192d21e0e4d82780:288:14)
我对@987654329@ 和subscribe 方法非常陌生,因为我一直在使用autopublish 包。我正在尝试转换,我遇到了很多困难。
【问题讨论】:
标签: javascript meteor