我在Http main.js中進行調用,並將此返回給我的控制檯「Uncaught TypeError:無法讀取null的屬性'set' 無法從中檢索信息我的http調用在函數本身之外。 感謝您的幫助。流星:如何使用來自模板中的Http調用的數據
Template.prod.onCreated(function prodOnCreated() {
var tmpl = this;
tmpl.data = new ReactiveVar;
HTTP.call('GET', 'https://localhost:9002/rest/v2/electronics/products/search/?query=:price-asc:category:575', {}, function(error, response) {
if (error)
console.log(error);
else {
console.log(response.data.products[0].code); // that works: display "2140285"
tmpl.data.set(response.data);// Doesn't work: message in the console "Uncaught TypeError: Cannot read property 'set' of null"
}
});
});
Template.prod.helpers({
data: function() {
console.log('Hi you are in the data function');
return Template.instance().data.get();
}
});
控制檯顯示:
main.js:40 Uncaught TypeError: Cannot read property 'set' of null(anonymous function) @ main.js:40(anonymous function) @ httpcall_client.js:83(anonymous function) @ underscore.js?hash=8de51f9…:784xhr.onreadystatechange @ httpcall_client.js:172
'tmpl.data = new ReactiveVar();'參見parancehesis – Sasikanth
Hi @Sasikanth我改正了它,並且我有同樣的錯誤 – Menahem770