[英]how to access meteor ReactiveVar variable in meteor call in onRendered
I want to access ReactiveVar variable in onRendered getting error Exception in delivering result of invoking 'getUsersData': TypeError: Cannot read property 'userData' of null 我想在onRendered中获取ReactiveVar变量获取错误在传递调用'getUsersData'的结果时出现异常:TypeError:无法读取null的属性'userData'
Template.editAdmin.onCreated(function() {
this.userData = new ReactiveVar([]);
});
Template.editAdmin.onRendered(function() {
Meteor.call("getUsersData", this.data, function(err, result) {
Template.instance().editAdminId.set(result);
});
});
It doesn't look like your code sample lines up with your error message. 看起来您的代码示例与您的错误消息不符。 You mentioned the error is: 你提到的错误是:
TypeError: Cannot read property 'userData' of null
but from looking at your code sample, I can see the error will really be: 但从查看您的代码示例,我可以看到错误将是:
TypeError: Cannot read property 'editAdminId' of null
I'll assume you want it working with userData
, so I'll adjust your code accordingly. 我假设您希望它与userData
一起使用,因此我会相应地调整您的代码。 Basically you want to make sure you're leveraging javascript closure properly when using Template.instance()
in your Method callback. 基本上,您希望确保在Method回调中使用Template.instance()
时正确利用javascript闭包。 For example: 例如:
Template.editAdmin.onCreated(function () {
this.userData = new ReactiveVar([]);
});
Template.editAdmin.onRendered(function () {
const instance = Template.instance();
Meteor.call("getUsersData", this.data, function (err, result) {
instance.userData.set(result);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.