问题描述
我现在正在拔头发.无法为我的备忘录应用显示单个备忘录详细页面.我尝试了数十种解决方案.有时我可以看到一毫秒的数据,然后它就消失了.我在 Iron Router 中做了路由
Im pulling my hair out right now.Cant get to display single memo detailed page for my memos app. I tried tens of solutions. Sometimes i can see data for a milisecond then it dissapears.I did route in Iron Router
// router.js
this.route('memo',{
path: '/memo/:_id',
data: function() { return Memos.findOne({id: this.params._id}); }
});
我写了助手(不知道为什么铁路由器会处理这个,对吗?)
I wrote helper ( not sure why if iron router handles this, right ? )
//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"
所以它似乎检索到正确的数据,但它没有被渲染 (?) ,我也不知道 wht 'NaN' 是在所有消息体前面做的.任何有关如何显示单个备忘录的帮助,非常感谢.
Cant get this to work. What am I missing here ?Console shows : "entering li body : zj9y3y3mNvQ6uK7Eg title: zxxxxxxxxxx" "**NaN**zxxxxxxxxxxxxxxx"
So it seems to retrive correct data but it doesnt get rendered (?) , also Ive no ide wht 'NaN' is doing in front of all messages bodies.Any help on how to get single memo displayed, much appreciated.
推荐答案
有一个错字:
Memos.findOne({id: this.params._id});
应该
Memos.findOne({_id: this.params._id});
或者只是
Memos.findOne(this.params._id);
这篇关于Meteor - 从备忘录列表中显示单个备忘录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!