1
votes

I have a view in Ember.js that looks like:

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

I need another view which is exactly the same, except it is called ForgotPassword, thus the only difference is the templateName.

Is there a way in Ember.js, I can say ForgotPassword inherits Login, and then just set templateName to forgotPassword?

Thanks.

1
BTW, within your didInsertElement/willDestroyElement, you should only be directly manipulating DOM elements that this this view's element or descendants, and when you do, use this.$(). e.g. this.$('input[name=email]'). - Luke Melia

1 Answers

2
votes

You can simply extend from the view you just created:

MyApp.YourOtherView = MyApp.LoginView.extend({
   // whatever you do here will be applied to `YourOtherView` only.. so
   templateName: 'other/template'
});