> ## Content Index
> Fetch the complete content index at: https://note.xdq.me/llms.txt
> Use this file to discover other available public pages before exploring further.

# ember 在加载页面后执行js方法
- URL: https://note.xdq.me/ember-zai-jia-zai-ye-mian-hou-zhi-xing-jsfang-fa/
- Published: 2014-12-03T22:24:57.000Z
- Updated: 2026-10-03T03:08:31.000Z
- Author: xud6
- Tags: ember, #Import 2026-10-03 02:45

在合适的地方加入一下代码

```
Ember.run.scheduleOnce('afterRender', this, afterRenderEvent);
afterRenderEvent : function(){
	// implement this hook in your own subclasses and run your jQuery logic 		there
}

```

可以加在model上

也可以加在view上

```
App.YourView = Ember.View.extend({
    didInsertElement : function(){
        this._super();
        Ember.run.scheduleOnce('afterRender', this, function(){
            // perform your jQuery logic here
        });
    }
});

```

也可以重写view对象（对所有view有效）

```
Ember.View.reopen({
      didInsertElement : function(){
          this._super();
          Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
      },
      afterRenderEvent : function(){
          // implement this hook in your own subclasses and run your jQuery logic there
      }
});

```