mardi 16 février 2016

How to slowly pass ember component a repeating list of data

Hey so im trying to pass a component different data in a rotation, so say I have a few objects in my controller class

a: {
   name: "a",
   number: 6
}
b: {
   name: "b",
   number: 15
}

And I want to pass them to a component in the template file:

{{my-component data=a}}

But I want to pass my-component the data in a loop of the data 'a' being displayed for 4 seconds, then the data of 'b' being displayed for 4 seconds, then just continuously repeating this until the page has been changed. A few thoughts on how I can do this, and which I have tried, but hasn't worked.

Using Ember.run.later and attempting to call the function (I get the error that 'self.function()' is not a function (Note this is in the actions section of the controller, it starts rotating when you click a button.):

 function: function(){
   var self = this;
   return self.get('test');
   Ember.run.later((function() {
     if(self.get('test'))
        self.set('test', false);
     else
        self.set('test', true);
     self.function();  // <-- Error is here
   }), 4000);
 }

And then using an if statement in the template:

   {{#if test}}
      {{my-component data=a}}
   {{else}}
      {{my-component data=b}}
   {{/if}}

So it runs this for the first time, but it never actually keeps rotating through these two data items. Help greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire