2015-06-24 155 views
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 

我不知道我錯過了什麼,我做錯了什麼。

+0

它是'waitOn',而不是'onWait'它需要返回訂閱:https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#the-waiton-option – fuzzybabybunny

+0

其實,你的很多代碼都是錯誤的。我強烈建議給鐵路由器指南一個閱讀 - https://github.com/iron-meteor/iron-router/blob/devel/Guide.md,並在發現流星書 - https:// www .discovermeteor.com/ – fuzzybabybunny

+0

@fuzzybabybunny謝謝,更新我的代碼,我看起來好像還沒有解決我的問題。它仍然給我相同的結果 –

回答

0

使用全局變量命名集合後,例如Reports = new Meteor.Collection('reports');,您應該使用該全局訪問服務器和客戶端的集合。

所以return Meteor.reports.find();在你的刊物上是錯誤的。它應該是:

return Reports.find(); 

查詢的其餘部分看起來沒問題。