【发布时间】:2016-11-20 19:45:48
【问题描述】:
我有这个代码
/* Template Helpers Start */
Template.ParticipationList.helpers({
getAllParticipants: function(){
var activityid = this._id;
Meteor.call('participation.findParticipants', activityid, function(error, result){
if(error){
console.log(error)
}
return result;
});
}
});
如果我将数组和 return 关键字放在流星调用之外,一切都很好 - 它将名称绑定到模板。但是什么时候是上面的,没有任何东西绑定到模板上。 我认为它与异步有关......但我做错了什么。
更新
<ul>
{{#each getAllParticipants}}
{{name}}
{{/each}}
</ul>
【问题讨论】:
-
几个小时前有人问过nearly identical question。
-
所以没有解决问题的办法。据说这是一个范围界定问题,但没有给出解决方案。
-
并非如此。这一切都归结为您的设计。每次调用助手调用一个方法并没有多大用处。如果您需要运行计算来获得某种状态,可能有更好的方法来做这件事。方法不是为获取数据而设计的。如果你想这样做,你可以让计算填充一个绑定到模板的反应字典,例如。
标签: asynchronous meteor callback helpers