最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I use Meteor.apply with options? - Stack Overflow

programmeradmin0浏览0评论

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 plete, 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);
    });
  }
});

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 plete, 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);
    });
  }
});
Share edited Jan 18, 2015 at 23:51 austin 5,8762 gold badges34 silver badges40 bronze badges asked Nov 14, 2014 at 8:50 zevsuldzevsuld 2764 silver badges15 bronze badges 2
  • 1 What does the method look like? – user3374348 Commented Nov 14, 2014 at 9:11
  • What error does it give and what does the method look like? – Marco de Jongh Commented Nov 14, 2014 at 11:07
Add a ment  | 

2 Answers 2

Reset to default 5

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){

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})
发布评论

评论列表(0)

  1. 暂无评论