Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.call("function",arg) not occurring synchronously

I'm currently not getting any return value for the following function, despite the suggestion that this is a synchronous call. If I do it asynchronously, (i.e. function(error, blah) { console.log(blah); }), I get the correct, intended output.

Template.file_nav.files = function(path) {
  path = path || "/";
  var x = Meteor.call('get_files', path);
  return x;
}  

Here's the server-side code for the "get_files" method:

  Meteor.methods( {
    get_files : function get_files(path) {
      return [
        { "name" : " bob" }, { "name" : "alice" },
      ];
    }

Also, here's the HTML part that's getting called correctly, in case it's relevant:

<template name="file_nav">
  <div>
    <ul style="dirnav">
    {{#each files}}
    {{#if isDirectory this}}
      <li><a href="javascript:void(0)" onclick="get_directory('{{name}}')">{{
    {{else}}
      <li><a href="javascript:void(0)" onclick="get_file('{{name}}')">{{name}
    {{/if}}
    {{/each}}
    </ul>
  </div>
</template>
like image 585
user1821985 Avatar asked Nov 03 '22 11:11

user1821985


1 Answers

If you read the body of the relevant docs (http://docs.meteor.com/#meteor_call) you'll see that it says:

"On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method"

So the behaviour you are seeing is what you should expect. I think the docs could be a little clearer here.

like image 188
Tom Coleman Avatar answered Nov 11 '22 04:11

Tom Coleman