2014-10-06 77 views
0

我正在构建一个简单的Emberjs网站没有逻辑或模型(为了学习的目的)。我有一个简单的路由器:Ember onLoad Without Views

MyApp.Router.map(function() { 
    this.route("page-one"); 
    this.route("page-two"); 
    this.route("page-three"); 
    this.route("page-four"); 
}); 

我有四个.hbs文件名称对应于每个路由。这很好。

但是,我想为四个页面中的每一个执行一些jQuery onLoad。我知道我需要使用视图和didInsertElement,但我的应用程序不使用任何视图。

是否可以使用didInsertElement没有意见?还是有一个我可以参考的主视图?

+0

不,视图是你需要/想要执行'didInsertElement'逻辑的地方。你可以安排一些'afterRender',但这是hackey http://stackoverflow.com/questions/17437016/ember-transition-rendering-complete-event/18385253#18385253 – Kingpin2k 2014-10-06 18:03:07

+0

这看起来很有帮助,我会试验。非常感谢@ Kingpin2k。 – Toby 2014-10-06 18:48:38

回答

0

基于@ Kingpin2k的link,我发现这个解决方案:

MyApp.IndexView = Ember.View.extend({ 
    setupSomething: function(){ 
    console.log("index elements inserted."); 
    }.on('didInsertElement') 
}); 

console.log进入这不仅导致当指数模板被渲染被添加。