【发布时间】:2015-05-19 00:51:41
【问题描述】:
我正在使用 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;
}
});
}
});
【问题讨论】:
-
在你得到事件错误之前,你能告诉我们“temp”是什么样的吗? console.log() 可能。
-
@TimC。感谢您的重播。我解决了这个问题。问题是临时变量不是数组。
标签: meteor meteor-blaze meteor-helper