4
我试过使用ReactiveVar。我不知道如何处理ReactiveVar。这里我试过的代码。Meteor ReactiveVar - TypeError:不能调用未定义的方法'set'
Template.Home.helpers({
names: function(){
temp = Template.instance().name.get();
return temp;
}
});
Template.Home.onCreated(function() {
this.name = new ReactiveVar();
Meteor.call("getNames", function(error, result) {
if(error){
alert("Oops!!! Something went wrong!");
return;
} else {
this.name.set(result); // TypeError: Cannot call method 'set' of undefined
return;
}
});
});
我是否正确设置并获得ReactiveVar?或如何设置和获取ReactiveVar?
我不得不创建一个变量来指向Template.instance()以获得ReactiveVar的工作,var instance = Template.instance();然后在Meteor.call的回调方法中引用该“实例” –