javascript - 如何在 Ember.js 中继承 View

标签 javascript ember.js

我在 Ember.js 中有一个如下所示的 View :

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

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

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

谢谢。

最佳答案

您可以简单地从刚刚创建的 View 扩展:

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

关于javascript - 如何在 Ember.js 中继承 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16471516/

相关文章:

javascript - Ember CLI Hook /事件错误

ember.js - Ember JS : Could not find property 'action'

ember.js - 引用 rootURL/hbs 中的任何绝对路径

javascript - Ember.js - 更改计算属性在运行时监听的内容

javascript - 使用 JavaScript 在 Internet Explorer 中插入外部 CSS

javascript - RequireJS:如何在模块级别声明依赖关系?

javascript - 带有 ReactJs 的 TinyMCE - onChange 事件只触发一次

javascript - 函数变量赋值结束时没有 ()

javascript - Ember数据加载路线时出错: TypeError: undefined is not a function

javascript - javascript 中按钮点击必须按顺序