我有困難與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