我正在使用 ReactiveVar。onCreated
我设置了 ReactiveVar with Meteor.Call
。当我尝试从 更改我的反应变量时event
,我Exception in delivering result of invoking 'namelist'
希望下面的代码能更多地解释我的问题。
模板:
<template name="Name">
{{#each list}}
Name : {{name}}
Age : {{age}}
{{/each}}
<button class="loadmore">Load More</button>
<template>
帮手:
Template.Name.helpers({
'list': function(){
return Template.instance().list.get();
}
})
已创建:
Template.Name.onCreated(function () {
this.limit = new ReactiveVar(5);
this.skip = new ReactiveVar(0);
this.list = new ReactiveVar();
Meteor.call("namelist", Template.instance().skip.get(), Template.instance().limit.get(), function(error, result) {
if(error){
alert("Oops!!! Something went wrong!");
return;
} else {
this.list.set(result);
this.skip.set(this.limit.get());
this.limit.set(this.limit.get()+5);
return;
}
}.bind(this));
});
事件 :
Template.Name.events({
'click .loadmore': function(event, template) {
Meteor.call("namelist", template.skip.get(), template.limit.get(), function(error, result) {
if(error){
alert("Oops!!! Something went wrong!");
return;
} else {
temp = template.list.get();
temp.push(result);
template.list.set(temp); // Here I am getting error of Exception in delivering result of invoking 'namelist'
template.skip.set(template.limit.get());
template.limit.set(template.limit.get()+5);
return;
}
});
}
});