0
im新增Nodejs/Meteor和Mongodb。 IM有這個問題,當我嘗試使用發佈和訂閱流星我不能讓我的數據流星發佈訂閱錯誤輸出
的lib/collection.js
Reports = new Meteor.Collection('reports');
的lib/routes.js
Router.map(function() {
this.route('dashboard', {
path: '/dashboard',
waitOn: function() {
return Meteor.subscribe('reports-limit', {limit: 5});
},
data: {
title:'Dashboard',
reports: function(){
console.log(Reports.find({}));
return Reports.find({});
}
},
action: function() {
if (this.ready()) {
this.render();
}
}
}); //end this.route
});//end Router map
服務器/ publisher.js
Meteor.publish('reports-limit', function(option){
var limit = options.limit;
return Meteor.reports.find({}, {sort: {date: -1}, limit: limit});
});
客戶端/模板/ dashboard.html
<Template name="dashboard">
<div class="content">
{{title}}
<ul>
{{#each reports}}
<li>{{_id}}</li>
{{/each}}
</ul>
</div>
</Template>
我不明白的ID和任何顯示的console.log()是給我
L…n.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined, matcher: M…o.Matcher, skip: undefined…}
結果
這是我安裝
$ meteor list
accounts-facebook 1.0.4 Login service for Facebook accounts
bootstrap 1.0.1 Front-end framework from Twitter
iron:router 1.0.9 Routing specifically designed for Meteor
meteor-platform 1.2.2 Include a standard set of Meteor packages in your app
monbro:mongodb-mapreduce-aggregation 1.0.1 Expose mongodb aggregation framework (mapReduce, aggregate and distinct), to SERVER si...
service-configuration 1.0.4 Manage the configuration for third-party services
包
我不知道我錯過了什麼,我做錯了什麼。
它是'waitOn',而不是'onWait'它需要返回訂閱:https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#the-waiton-option – fuzzybabybunny
其實,你的很多代碼都是錯誤的。我強烈建議給鐵路由器指南一個閱讀 - https://github.com/iron-meteor/iron-router/blob/devel/Guide.md,並在發現流星書 - https:// www .discovermeteor.com/ – fuzzybabybunny
@fuzzybabybunny謝謝,更新我的代碼,我看起來好像還沒有解決我的問題。它仍然給我相同的結果 –