【发布时间】:2023-04-05 18:46:01
【问题描述】:
我在 Http main.js 中进行调用,这会将我返回到我的控制台“未捕获的类型错误:无法读取属性‘set’ of 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: Cannot read property 'set' of null(匿名函数)@main.js:40(匿名函数)@ httpcall_client.js:83(匿名函数)@ underscore.js?hash=8de51f9…:784xhr.onreadystatechange @ httpcall_client.js:172
【问题讨论】:
-
tmpl.data = new ReactiveVar();见括号 -
嗨@Sasikanth 我纠正了它,我有同样的错误
标签: javascript http meteor xmlhttprequest