Using Ember.js, how do I run some JS after a view is rendered?

前端 未结 5 1324
我寻月下人不归
我寻月下人不归 2020-11-28 06:55

How do I run a function after an Ember View is inserted into the DOM?

Here\'s my use-case: I\'d like to use jQuery UI sortable to allow sorting.

5条回答
  •  半阙折子戏
    2020-11-28 07:17

    You need to fire whatever you want in the didInsertElement callback in your View:

    MyEmberApp.PostsIndexView = Ember.View.extend({
    
      didInsertElement: function(){
        // 'this' refers to the view's template element.
        this.$('table.has-datatable').DataTable();
      }
    
    });
    

提交回复
热议问题