Javascript 通过iron显示操作:路由器,模板isn';t从collection.findOne方法传递数据
我无法在模型实例的“显示”页面中获取用于显示其数据的链接 以下是不会显示其数据的模板:Javascript 通过iron显示操作:路由器,模板isn';t从collection.findOne方法传递数据,javascript,meteor,handlebars.js,iron-router,Javascript,Meteor,Handlebars.js,Iron Router,我无法在模型实例的“显示”页面中获取用于显示其数据的链接 以下是不会显示其数据的模板: <template name="priority"> <h1>Priority: {{title}}</h1> </template> Meteor.method非常简单,它只查询可变优先级: 包含href的视图如下所示: <template name="priorityList"> <ul class="table-view">
<template name="priority">
<h1>Priority: {{title}}</h1>
</template>
Meteor.method非常简单,它只查询可变优先级:
包含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>
哦,我应该提到的是,我还尝试使用waitOn
方法,因为我认为我可能在加载数据之前加载模板,但这也没有帮助
Router.configure({
...
waitOn: function(){
return Meteor.subscribe('priorities');
}
});
这么多代码,只是为了显示发生了什么
这是怎么回事?为什么我的“显示”模板不给我任何数据?将您的路径更改为此
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()上的所有内容
以上只是一个示例,因此您可以了解这个想法,但它应该可以工作,因为您期望\u id:priority
和\u id:this.params.\u id
是相同的
只需确保删除了自动发布包即可
并按顺序排列订阅/发布
Meteor.publish('Menu', function(){
return Priorities.find();
});
“showPriority”:函数(priority){return Priorities.findOne({name:'priority.show'});}是我在Meteor.methods对象中尝试的。我的模板仍然没有呈现优先级=(卡在我的工作中,很快将在家中尝试此功能)的标题
Router.configure({
...
waitOn: function(){
return Meteor.subscribe('priorities');
}
});
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
}
}
});
});
Meteor.publish('Menu', function(){
return Priorities.find();
});