Meteor - 从备忘录列表中显示单个备忘录页面

时间:2014-09-19 03:02:39

标签: javascript meteor

我现在正把头发拉出来。 无法显示我的备忘录应用程序的单个备忘录详细页面。我尝试了几十个解决方案。有时我可以看到数据一毫秒然后它消失了。 我在Iron Router中进行了路由

// 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"因此它似乎可以检索正确的数据,但它不会被渲染(?),也没有想法,但是没有#Na&#39; NaN&#39;正在所有消息体前面做。 有关如何显示单个备忘录的任何帮助,非常感谢。

1 个答案:

答案 0 :(得分:1)

有一个拼写错误:

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

应该是

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

或只是

Memos.findOne(this.params._id);