use*_*985 5 javascript node.js meteor
我目前没有获得以下函数的任何返回值,尽管有人建议这是同步调用.如果我异步执行,(即函数(错误,等等){console.log(blah);}),我得到正确的预期输出.
Template.file_nav.files = function(path) {
path = path || "/";
var x = Meteor.call('get_files', path);
return x;
}
Run Code Online (Sandbox Code Playgroud)
这是"get_files"方法的服务器端代码:
Meteor.methods( {
get_files : function get_files(path) {
return [
{ "name" : " bob" }, { "name" : "alice" },
];
}
Run Code Online (Sandbox Code Playgroud)
此外,这是正确调用的HTML部分,如果它是相关的:
<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>
Run Code Online (Sandbox Code Playgroud)
如果您阅读相关文档的正文(http://docs.meteor.com/#meteor_call),您会看到它说:
“在客户端,如果您不传递回调并且不在存根内,则调用将返回未定义,并且您将无法获取该方法的返回值”
因此,您所看到的行为是您应该期望的。我认为这里的文档可能会更清楚一些。
| 归档时间: |
|
| 查看次数: |
1149 次 |
| 最近记录: |