【发布时间】:2015-05-07 08:57:55
【问题描述】:
返回值正在控制台中打印。但它不显示在模板中
我的模板
<template name="Mytemplate">
<ul>
{{#each Name}}
<li>{{this}}</li> //No display
{{/each}}
</ul>
</template>
js
Template.Mytemplate.helpers({
Name : function(){
Meteor.call("getnNames", function(error, result) {
if(error){
alert("Oops!!! Something went wrong!");
return;
}else{
console.log(result); // Got result in array ["john","smith"]
return result;
}
});
}
});
我的回报是对的吗?或者怎么做?
【问题讨论】:
-
从这段代码中,它应该可以工作。一定有其他我们看不到的事情发生。
-
重点是,您不能在模板助手中调用服务器方法。我的意思是你可以,但不会在模板上得到输出,这几乎违背了目的。有几个解决方法。看看this question and answers
-
永远不要从帮助程序更改您的“应用程序状态”(例如设置会话或调用方法)。助手是表示当前数据状态的一种方式。
标签: javascript meteor meteor-helper