0

ReactiveVar を使用しています。onCreatedReactiveVar を設定しwith Meteor.Callました。リアクティブ変数を から変更しようとすると、以下のコードで問題が詳しく説明されることを願っていますeventException 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;
      }
    });
  }
});
4

1 に答える 1

2

コードを実行しないと、何が起こっているのか正確にはわかりませんが、イニシャルが配列にMeteor.call設定されていない可能性があります。listさらに、tempなしで宣言さvarれているため、グローバル名前空間に漏れています。イベント ハンドラーで、次のように記述してみてください。

var temp = template.list.get() || [];
temp.push(result);
template.list.set(temp);
于 2015-05-18T16:51:41.083 に答える