我无法获得该节目'显示其数据的模型实例的页面。
以下是不会显示其数据的模板:
<template name="priority">
<h1>Priority: {{title}}</h1>
</template>
它本身非常简单,但我无法显示标题。 Iron:路由器负责使用以下代码将我们引导到此页面:
Router.route('/priority/:_id', function(){
var priority = this.params._id;
this.render('priority', {
data: function(priority){
Meteor.call('showPriority', priority, function(error){
if (error) {
console.log("An error has occured: " + error);
}
})
}
})
}, {
name: 'priority.show'
});
Meteor.method非常简单,只是查询变量 priority :
'showPriority': function(priority) {
return Priorities.findOne({_id: priority});
}
带有href的视图在这里:
<template name="priorityList">
<ul class="table-view">
{{#each this}}
<li class="table-view-cell">
{{title}}
<a href="{{pathFor route="priority.show"}}"><span class="pull-right icon icon-edit"></span></a>
</li>
{{/each}}
</ul>
</template>
请注意,此视图会显示所有优先级的列表。当我检查href时,所有路径都是使用_id
:
<a href="/priority/yYihyZmZ2xkAso7i5">...
哦,我应该提一下,我也尝试使用waitOn
方法,因为我以为我可能会在数据之前加载模板,但这对...没有帮助...... / p>
Router.configure({
...
waitOn: function(){
return Meteor.subscribe('priorities');
}
});
这么多代码,只是为了表明发生了什么!
这里的交易是什么?为什么赢得了我的&#34; show&#34;模板给我任何数据?
答案 0 :(得分:2)
改变您的路线。
Router.map(function () {
this.route('priority', {
path: '/priority/:_id',
waitOn: function(){
return Meteor.subscribe('priorities',this.params._id);
},
data: function(){
if(this.ready()){
return Priorities.findOne({_id: this.params._id});
}else{
this.render('loading') //if data not ready we render some loading template
}
}
});
});
您不需要为find();
制作Meteor.call,而是data:function()
上的所有内容
以上只是一个示例,因此您可以了解相关信息,但它应该有效,因为您期望_id:priority
和_id:this.params._id
相同。
确保已删除自动发布包。
并按顺序排列subscriptions/publish
。
Meteor.publish('Menu', function(){
return Priorities.find();
});