How to access 'this' tag instance inside tag lifecycle event?

93 views Asked by At

I'm trying to update an array every time my tag receives an update from parent tags. Here is my code:

var tag = function(opts){
  this.set = [];
  var self = this;

  this.on('updated', function(){
    var obj = opts.my_topics;
    var better_obj = {};
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        var topic_title = key;
        better_obj = obj[key];
        better_obj['title'] = key;
      }
    }
    self.set.push(better_obj);
  })
}

Whenever I try to push(), I get an error: Uncaught SyntaxError: Unexpected token ; database.js:60. The moment I remove the line of code for the push, the error disappears. Am I using this/self wrong in this case or could it be something else?

What I am trying to accomplish here is taking an object from opts (which receives regular updates), converting into an array, and using it for an each loop within my tag. I do not know how to do this other than a) what i'm trying to do now by accessing this, or b) rewiring my opts to deliver an array rather than an object (which is currently failing for me as I'm using Redux and it doesn't like dispatching non-objects).

0

There are 0 answers