How to access meteor ReactiveVar variable in meteor call in onRendered

I want to access the ReactiveVar variable in onRendered get error An exception occurred while delivering the result of the call to 'getUsersData': TypeError: Unable to read the userData property from null

    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);
      });
   });
+4
source share
1 answer

This is not like your sample code is aligned with the error message. You mentioned the error:

TypeError: Cannot read property 'userData' of null

but looking at the sample code, I see that the error will be valid:

TypeError: Cannot read property 'editAdminId' of null

, , userData, . , Template.instance() javascript. :

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);
  });
});
+1

Source: https://habr.com/ru/post/1651527/


All Articles