我有困难与Meteor.call
回调的工作。我定义了一个从服务器端检索值的函数;但是,它不会将它们返回到模板,以便通过{{#each}}
循环对它们进行循环。Meteor.call()回调没有返回值模板
下面是函数:
search: function() {
Meteor.call('mySearchFunction', arg1, function(err, res) {
if (err) console.log(err);
else if(res) {
console.log(res);
return res;
}
});
}
的console.log(res)
让我发现我所需要的数据,这是与mySearchFunction
正确牵强,但我不能把它传递给模板处理器,尽管它是一个数组这可能会被迭代。所以,我试过如下:
search: function() {
var s = Meteor.call('mySearchFunction', arg1, function(err, res) {
if (err) console.log(err);
else if(res) {
console.log(res);
return res;
}
});
console.log(s);
return s;
}
而且console.log(res)
继续显示必要的数据,但console.log(s)
显示为undefined
。我认为这是因为在res
得到机会被评估服务器端之前流星的异步性质返回s
。无论哪种方式,奇怪的是我无法从辅助函数中存储的帮助器中返回数据。
ARG1只是一个字符串,不知道是否有差别,我想你的解决方案现在...... – nmac 2015-03-30 21:34:26
我解决了从您提到的问题的回答我的问题。 +1。 – nmac 2015-03-30 21:39:26