Reactive var on method.call

Template.project.onCreated(function(){
  this.result_array=new ReactiveVar([]);
});

Template.project.helpers({
  projectlist:function(){
    Meteor.call("project.list", function(error, result){
      if(error){
        console.log("error", error);
      }
      if(result){
        console.log(Template.instance().result_array.get());
        Template.instance().result_array.set(result);
      }
    });
    console.log(  Template.instance().result_array.get());
    return   Template.instance().result_array;

  },

});
Server Js
Meteor.methods({
  'project.list':function(){
return  [{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},{project:'jxchvbxc'},]
  }
});

But I got > Exception in defer callback: badSequenceError
And Exception in delivering result of invoking ‘project.list’

If you try to return on helper what you have on the “result_array” ReactiveVar … the helper will run every time the “result_array” changes (in your case, when you set it up on “if(result)” block).

You can just call the method and return the result or you can call the method on onCreated and set the result on “result_array” ReactiveVar.

1 Like