我從流星中的wrapAsync函數獲取返回值時遇到了問題。以下是我的代碼流星從異步函數中獲取值
Template.greet.helpers({
greet : function() {
var convertAsyncToSync = Meteor.wrapAsync(HTTP.get);
resultOfAsyncToSync = convertAsyncToSync('http://www.demo.com/api/greet', {});
console.log(resultOfAsyncToSync);
return resultOfAsyncToSync;
}
});
我在控制檯中得到未定義的值。
使用reactiveDict或reactiveVar保存值 – Sasikanth
感謝您的答覆。我嘗試了下面的代碼,但我仍然無法從中得到任何東西。 Template.greet.helpers({ 的greet:函數(){ VAR convertAsyncToSync = Meteor.wrapAsync(HTTP.get); resultOfAsyncToSync = convertAsyncToSync( 'http://www.demo.com/api/greet',功能(錯誤,響應){ alert('response'); console.log(response); return response.data; }); } }); 現在我的反應被打印在控制檯中,但沒有任何返回模板 – Subhash