Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Meteor.apply with options?

I am using Meteor.call method for invoking a function on server. It is kind of working, however it seems like result is not fully returning. (Expecting length of 250, now it returning 11, 121, something like that) I am using async Meteor.call. I am guessing before server side function complete, Meteor.call is returning a result. I tried sync call but I'm not clearly understand the Meteor docs.

So I am trying to use Meteor.apply() with options. How can I use Meteor.apply with options? Any examples?

client.js

var chartData;
Template.prodSelect.events({
  'click': function(e){
    e.preventDefault();
    var prodName = document.getElementById("productSelect").value;
    //console.log(prodName);
    Meteor.call('chartData', prodName,function(err,data){
      if (err)
        console.log(err);
      chartData = JSON.parse(data);
      //console.log(data);
      createChart(chartData);
    });
  }
});

Tried this , but is gives error.

var chartData;
Template.prodSelect.events({
  'click': function(e){
    e.preventDefault();
    var prodName = document.getElementById("productSelect").value;
    //console.log(prodName);
    Meteor.apply('chartData', prodName,{wait: true}, function(err,data){
      if (err)
        console.log(err);
      chartData = JSON.parse(data);
      //console.log(data);
      createChart(chartData);
    });
  }
});
like image 748
zevsuld Avatar asked Nov 14 '14 08:11

zevsuld


2 Answers

In order not to receive Malformed method invocation error, you should pass arguments as an array. And in addition to @robut's answer:
It's still best to see what options you are passing, thus I prefer:

Meteor.apply('addPost',[] ,{wait:true})
like image 44
avalanche1 Avatar answered Oct 22 '22 19:10

avalanche1


Just figured this out myself. You need to pass the arguments as an array, and to specify "wait", you just pass true to the function. So, in your case:

Meteor.apply('chartData', [prodName], true, function(err, result){

like image 111
robut Avatar answered Oct 22 '22 19:10

robut