【发布时间】:2014-01-18 17:17:35
【问题描述】:
这其实是两个问题:
是否可以在 Iron Router 的 waitOn 选项中有条件地订阅集合?
是否可以在 Router.go() 中将对象作为参数传入?
在我的应用中创建新帖子时,我正在尝试减少呈现视图的延迟。我尝试传入一个 isNew 属性作为 Router.go() 的参数,但没有运气:
// Router call after creating a new post
Router.go('postPage', {
_id: id,
isNew: true,
post: newPostObject
});
// router.js
Router.map(function() {
this.route('postsList', {
path: '/'
});
this.route('postPage', {
path: '/:_id',
waitOn: function() {
//This returns only _id for some reason.
console.log(this.params);
if (this.params.isNew != true) {
return [
Meteor.subscribe('singlePost', this.params._id),
Meteor.subscribe('images', this.params._id),
]
}
},
data: function() {
if (this.params.isNew == true) {
return this.params.post
else {
return Posts.findOne(this.params._id);
}
}
});
});
【问题讨论】:
标签: javascript meteor iron-router