Javascript 如何在Ember.js中继承视图
我在Ember.js中有一个视图,看起来像:Javascript 如何在Ember.js中继承视图,javascript,ember.js,Javascript,Ember.js,我在Ember.js中有一个视图,看起来像: MyApp.LoginView = Ember.View.extend({ templateName: 'login', didInsertElement: function() { $("body").addClass("light-bg"); $("footer").css("display", "none"); $("input[name=email]").focus(); }, willDestroyE
MyApp.LoginView = Ember.View.extend({
templateName: 'login',
didInsertElement: function() {
$("body").addClass("light-bg");
$("footer").css("display", "none");
$("input[name=email]").focus();
},
willDestroyElement: function() {
$("body").removeClass("light-bg");
$("footer").css("display", "block");
}
});
我需要另一个完全相同的视图,除了它被称为放弃密码
,因此唯一的区别是模板名
在Ember.js中,我可以说放弃密码
继承登录
,然后将templateName设置为放弃密码
谢谢。您只需从刚才创建的视图中扩展:
MyApp.YourOtherView = MyApp.LoginView.extend({
// whatever you do here will be applied to `YourOtherView` only.. so
templateName: 'other/template'
});
顺便说一句,在您的
didInsertElement
/willDestroyElement
中,您应该只直接操作此视图的元素或子体的DOM元素,并且在操作时,使用this.$()
。e、 g.this.$('input[name=email]')
。