embergal
embergal

Reputation: 159

Ember js how can i run a function after model change?

I am using materialize css library and it says

Collapsible elements only need initialization if they are added dynamically

And i add some elements dynamically. So after the view is rendered i should run this function:

$('.collapsible').collapsible({
  accordion : false 
});

In setupController function i make some requests and after every request finished i setup the controller. When controller gets the model and after the view is rendered with the new model data i should run a function to initialize the ui elments

Upvotes: 1

Views: 271

Answers (1)

Timm
Timm

Reputation: 1015

You have to setup an ember.js component for your accordion and use the didInsertElement hook:

export default Ember.Component.extend({
  classNames: ['.collapsible'],
  didInsertElement() {
    Ember.run.scheduleOnce('afterRender', this, function() {
      this.$().collapsible({
        accordion: false
      });
    });
  },     
});

Upvotes: 3

Related Questions