TJR*_*TJR 6 meteor iron-router
我正在寻找一个解决方案,铁路由器在渲染之前正在等待我的集合上的成功查找方法.
我的路线看起来像这样:
this.route('business', {
path : '/business/:type/:_id',
waitOn : function () {
return Meteor.subscribe('business', this.params._id);
},
data : function () {
return Business.findOne({_id: this.params._id});
}
});
Run Code Online (Sandbox Code Playgroud)
这很好用.铁路由器似乎在等待Collection的订阅,以便为客户端获取正确的文档.但是我的模板中需要的数据延迟了findOne函数.
Template.businessItemItem.rendered = function () {
console.log(Router.current().data()); // undefined
window.setTimeout(function(){
console.log(Router.current().data()); // [Object]
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
解决方案 对于遇到同样问题的每个人 只需为您的路线添加"action"方法,如下所示:
action : function () {
if (this.ready()) this.render();
}
Run Code Online (Sandbox Code Playgroud)
有了这个方法,一切都适合我.
| 归档时间: |
|
| 查看次数: |
2703 次 |
| 最近记录: |