【发布时间】:2016-03-31 06:01:47
【问题描述】:
我在流星模板管理器中有这样一段代码:
"click #refuse": function() {
Meteor.call("removeUserFromEvent", this._id, Meteor.userId());
if (Template.instance().data.participants.length === Template.instance().data.orderedParticipants.length) {
Meteor.call("updateEventStatus", this._id, "ordered");
}
Router.go("/");
}
我想让if(...){...} 的东西在Meteor.call(...) 回调中执行,比如
"click #refuse": function() {
Meteor.call("removeUserFromEvent", this._id, Meteor.userId(), function(){
if (Template.instance().data.participants.length === Template.instance().data.orderedParticipants.length) {
Meteor.call("updateEventStatus", this._id, "ordered");
}
});
Router.go("/");
}
但如果我尝试这样做,结果是在该回调内部 Template.instance() 返回 null 并且我无法从模板中获取数据。
我怎样才能在方法回调中放置这些东西(我的意思是,获取一些当前状态参数并取决于这些调用或不调用另一个方法)?也许 Template.instance().data 是存储状态参数的错误位置? Template.instance.data 是响应式的吗?或许我应该以某种方式更改架构,以使此类功能能够驻留在回调中?
【问题讨论】:
标签: javascript meteor