2014-09-19 86 views
0

我現在拉出我的頭髮。 無法顯示我的備忘錄應用程序的單一備忘錄詳細頁面。我嘗試了數十種解決方案。有時我可以看到數據一毫秒然後消失。 我在鐵路由器流星 - 從備忘錄列表中顯示單個備忘錄頁

// router.js 

    this.route('memo',{ 
     path: '/memo/:_id', 
     data: function() { return Memos.findOne({id: this.params._id}); } 
    }); 

我寫的幫手做路線(不知道爲什麼,如果鐵路由器處理這個,是吧?)對整個列表

//helpers.js 

    Template.memo.helpers({ 
     memo: function(){ return Memos.findOne({id: this._id})} 
    }); 

Template.memos.events({ 
    'click #remove-memo': function(event,template){ 
     console.log('memo removed : ' + this._id); 
     Memos.remove(this._id); 
    }, 
    **'click #li-body': function(event, template){ 
     console.log('entering li body : ' + this._id + ' title: ' + this.title); 
     Router.go('/memo/'+this._id); 
    }** 
}); 

模板

//memos.html 
    <template name="memos"> 
     <ul> 
      {{#each memos}} 
      <li class="notes-main"> 
       <span id="remove-memo" class="ex icon-close"></span> 
       <a class="no-decoration" **href="{{pathFor 'memo' }}**"> 
       <span id="li-body" class="no-decoration"> 
        <span class="notes-title">{{this.title}}</span> 
        <span class="notes-author">{{author}}</span> 
        <span class="notes-body-prev">{{body}}</span> 
       </span> 
       </a> 
      </li> 
      {{/each}} 
     </ul> 
    </template> 

然後單個備忘錄模板

//memo.html 

<template name="memo"> 
    title : {{title}} 
    <br> 
    body: {{body}} 

</template> 

無法讓此工作。我在這裏錯過了什麼? 控制檯顯示:"entering li body : zj9y3y3mNvQ6uK7Eg title: zxxxxxxxxxx" "**NaN**zxxxxxxxxxxxxxxx"因此,它似乎檢索正確的數據,但它沒有得到渲染(?),也沒有'NaN'在所有消息體前做的事情。 任何幫助如何獲得單一的備忘錄,非常感謝。

+0

你有一個'在你的HTML中,每memos',但我沒有看到'備忘錄'助手。這是在你的代碼? – 2014-09-19 03:41:27

+0

是的,備忘錄幫手工作得很好。我可以看到所有備忘錄的清單,問題是單一的詳細備忘錄。 – yoK0 2014-09-19 03:45:26

回答

1

有一個錯字:

Memos.findOne({id: this.params._id}); 

應該

Memos.findOne({_id: this.params._id}); 

或只是

Memos.findOne(this.params._id); 
+0

Memos.findOne(this.params._id)解決了這個問題。我想有時候我們需要別人的新面貌。謝謝 – yoK0 2014-09-19 04:06:52