0

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).

skwny
  • 2,930
  • 4
  • 25
  • 45
  • Is that a tag file? the syntax doesn't look right to me. Why are you using var tag = function(opts){ ? if it's a tag file you don't need that – vitomd Dec 16 '16 at 23:56
  • @vitomd It is a separate .js file for a tag. In my .html file I have: ``. This is a solution I found in order to separate the two. In any case, does this affect my ability to grab `this` inside a tag lifecycle event handler? – skwny Dec 17 '16 at 03:23
  • I don't know exactly how that works. I would try using the tag directly and see if it's work, because I'm not sure how Riot.js is compiling your tags in your sample. – vitomd Dec 17 '16 at 21:55

0 Answers0