1

我在 Ember.js 中有一个看起来像这样的视图:

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");
  }
});

我需要另一个完全相同的视图,除了它被称为ForgotPassword,因此唯一的区别是templateName.

Ember.js 中有没有办法,我可以说ForgotPassword继承Login,然后将 templateName 设置为forgotPassword

谢谢。

4

1 回答 1

2

您可以简单地从刚刚创建的视图中扩展:

MyApp.YourOtherView = MyApp.LoginView.extend({
   // whatever you do here will be applied to `YourOtherView` only.. so
   templateName: 'other/template'
});
于 2013-05-09T21:41:42.393 回答