我有一个使用 Flow Router 及其发布/订阅机制的应用程序。我还有一个集合和模板助手。代码在客户端
Template.theCase.helpers({
theCase: function () {
var id = FlowRouter.getParam('id');
var theCase = Cases.findOne({
id: id
});
return theCase;
}
});
和
{{#with theCase}}
{{ id }}
{{/with}}
然后,在服务器上
Meteor.publish('theCase', function (id) {
return Cases.findOne({
id: id
});
});
最后,在两者上 ( lib
)
FlowRouter.route('/case/:id', {
subscriptions: function (params) {
this.register('theCase', Meteor.subscribe('theCase', params.id));
},
action: function (params, queryParams) {
return BlazeLayout.render('container');
}
});
正如我所看到的,问题在于 helper 返回undefined
,因为不允许通过 . 以外的任何其他属性在集合中查找项目_id
。我怎样才能克服它?我已经阅读了大量关于 pub/sub、helpers 和 routing 的官方文档,但我找不到解决方案。有什么建议么?