How to use Meteor.apply with options?

I use the Meteor.call method to call a function on the server. This is a kind of work, however, it seems that the result is not fully returning. (Expecting a length of 250, now it returns 11, 121, something like that) I use async Meteor.call . I guess that before completing the server-side function, Meteor.call returns the result. I tried to synchronize the call, but I do not quite understand the Meteor docs.

So, I'm trying to use Meteor.apply() with parameters. How to use Meteor.apply with parameters? 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 gives an 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); }); } }); 
+5
source share
2 answers

Just thought about it. You need to pass the arguments as an array, and to indicate "wait", you simply pass true function. So in your case:

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

+4
source

In order not to get the Malformed method invocation error, you must pass the arguments as an array. And in addition to @robut answer:
I'm still better off seeing what options you go through, so I prefer:

 Meteor.apply('addPost',[] ,{wait:true}) 
0
source

Source: https://habr.com/ru/post/1206862/


All Articles