我对 emberjs 还很陌生,在尝试使用 didInsertElement 事件时偶然发现了一个问题。
我创建了一个 JSFiddle,您可以在其中看到车把模板已实际呈现,但在 ApplicationView 和 HomeView 中都没有调用 didInsertelement 事件。
JSFiddle:http: //jsfiddle.net/QZZFY/3/
或者如果链接断开,我的代码:
html:
<script type="text/x-handlebars" data-template-name="container">
<!-- Imagine theme header content here -->
{{outlet "leftContent"}}
<!-- some more code here -->
{{outlet "pageContent"}}
<!-- and here -->
{{outlet "rightContent"}}
<!-- and a footer here -->
</script>
<script type="text/x-handlebars" data-template-name="leftSidebar">
<p>A left sidebar</p>
</script>
<script type="text/x-handlebars" data-template-name="rightSidebar">
<p>A right sidebar</p>
</script>
<script type="text/x-handlebars" data-template-name="homepageContent">
<p>This is the {{pageTitle}}!</p>
</script>
Javascript:
Ember.LOG_BINDINGS = false;
MyApp = Ember.Application.create();
MyApp.Router.map(function() {
//Home Page
this.route("home", { path: "/" });
});
//=======================
//= ROUTES =
//=======================
MyApp.ApplicationRoute = Ember.Route.extend({
renderTemplate: function() {
this.render("container");
this.render('leftSidebar', { outlet: 'leftContent', into: 'container' });
this.render("rightSidebar", { outlet: 'rightContent', into: 'container' });
}
});
MyApp.HomeRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('pageTitle', "homepage");
},
renderTemplate: function() {
this.render('homepageContent', { outlet: 'pageContent', into: 'container' });
}
});
//=======================
//= CONTROLLERS =
//=======================
MyApp.ApplicationController = Ember.Controller.extend();
MyApp.HomeController = Ember.Controller.extend();
//=======================
//= VIEWS =
//=======================
MyApp.ApplicationView = Ember.View.extend({
didInsertElement: function(event) {
console.debug("Applicationview didInsertElement() called");
}
});
MyApp.HomeView = Ember.View.extend({
didInsertElement: function(event) {
console.debug("Homeview didInsertElement() called");
}
});
我究竟做错了什么?