在Meteor中,我将数据库中的两个对象发送到模板:
Template.myTemplate.helpers({
helper1: function() {
var object1 = this; // data context set in iron:router...path is context dependent
// modify some values in object1
return this;
},
helper2: function() {
return Collection2.find({_id: this.object2_id});
}
});
Run Code Online (Sandbox Code Playgroud)
该模板还有一个事件处理程序来修改上面的两个对象.我试图从上面访问helper1和helper2,但如果我调用模板的数据上下文,我只能访问未修改版本的object1.如何访问上面定义的帮助程序?
Template.myTemplate.events({
'submit form': function(event) {
event.preventDefault();
// Access helper2 object and attributes here instead of calling Collection2.find() again
}
});
Run Code Online (Sandbox Code Playgroud)