chackerian
chackerian

Reputation: 1401

Receiving data from server method on client

I have the following Meteor method making use of the color-namer npm package to find the name of a color from a hex value.

colorName: function (options) {
  var Namer = Meteor.npmRequire('color-namer');
  var name = Namer(options.color);
  var color = name.basic[0].name;
  return color;
}

On the client side I have a form with a color selector which saves all options in the options object. The color value is saved as options.color.

I call my method like so:

Meteor.call( 'colorName', options.color);

When the form is submitted I would like to get the returned color from the server method and then rewrite the options.color value.

Specifically my idea would be to use options.color = color but the color returned from the server seems to be non accessible in the client.

I am unsure of how to access this var color value that is created on the server and not the client. Maybe I am thinking about the problem in the wrong way and have the wrong approach and the right tools.

Upvotes: 0

Views: 39

Answers (1)

Christian Fritz
Christian Fritz

Reputation: 21354

You may not have realized yet that you need a callback function on the client, in order to receive the result of the method:

Meteor.call( 'colorName', options.color, function(err, result) {
   if (!err) {
       // result is "color" on the server, do what you want with it
   } 
});

Upvotes: 1

Related Questions