2014-09-25 104 views
0

此問題與前面提到的this one類似。我得到了它的工作,複製解決方案,但是我必須在這裏失去一些東西。我開始與代碼:文字閃爍並消失

router.js:

this.route('note',{ 
    path: '/note/:_id', 
    data: function() { return Notes.findOne(this.params._id); }, 
}); 
this.route('notes', { 
    waitOn: function() { return Meteor.subscribe('notes')} 
}); 

模板的 '注意':

<table id="notes-table"> 
    {{#each notes}} 
     <tr id="table-row"> 
      <td id="indicator"></td> 
      <td id="remove-note" class="icon-close notes-table-class"></td> 
      <td id="notes-title" class="Nbody notes-table-class">{{this.title}}</td> 
      <td id="notes-body-prev" class="Nbody notes-table-class">{{this.body}}</td> 
     </tr> 
    {{/each}} 
</table> 

helpers.js:

Template.notes.events({ 
    'click .Nbody': function(events,template){ 
     console.log('displaying note : ' + this._id); 
     Router.go('/note/'+this._id); 
    } 
}); 

模板 '筆記' 很簡單{{title}}和{{body}}

問題是,當我點擊筆記表體時,它確實把我的位置,這是單注,但它的文本只是閃爍一秒鐘,立即消失,永遠不會回來,所以我什麼都看不到。 問題:問題是什麼?

我在控制檯中沒有得到任何錯誤。

這一點,「備忘錄」的解決方案之間的差異是: - 通過表代替跨度的 這兒IM - 我放棄了在的標籤纏繞點擊體(我認爲這可能是原因)

+0

您是否刪除了自動發佈?如果是這種情況,您在哪裏訂閱Notes集合? – saimeunt 2014-09-26 00:00:04

+0

自動發佈,查看全部刪除。我更新了我的帖子,以便我可以看到我在哪裏訂閱。這讓我想到了,當我將waitOn移到Router.configure時,它開始工作。如果你不介意寫出建設性的答案來幫助別人,並且我也可以評價它,那會很好。謝謝。 – yoK0 2014-09-26 00:38:24

回答

1

你有在 '筆記' 訂閱路線能夠檢索它:

客戶端:

this.route('note',{ 
    path: '/note/:_id', 
    waitOn: function() { return Meteor.subscribe('note',this.params._id)} 
    data: function() { return Notes.findOne(this.params._id); }, 
}); 
this.route('notes', { 
    waitOn: function() { return Meteor.subscribe('notes')} 
}); 

服務器:

Meteor.publish('note', function(noteId){ 
    return Notes.find(this.params._id); 
}) 

在評論中你寫道,當你開始工作時:moved waitOn to Router.configure。 Route.configure waitOn適用於所有路由,因爲Method.publish('notes')函數可能返回Notes.find(),則note開始正常工作。