我在Http main.js中调用,这使我回到我的控制台“Uncaught TypeError:无法读取属性'set'为null” 无法从函数本身之外的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:无法读取属性'set' null(匿名函数)@main.js:40(匿名函数)@ httpcall_client.js:83(匿名函数)@ underscore.js?hash = 8de51f9 ...:784xhr.onreadystatechange @ httpcall_client.js:172
答案 0 :(得分:0)
首先,你需要使用下面的
添加一个包meteor add reactive-var
然后你可以像
那样初始化反应变量tmpl.data = new ReactiveVar();