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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With