2013-05-09 43 views
1

繼承一個觀點我在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(); 
    }, 
    willDestroyElement: function() { 
    $("body").removeClass("light-bg"); 
    $("footer").css("display", "block"); 
    } 
}); 

我需要另一種觀點認爲這是完全一樣的,只是它被稱爲ForgotPassword,因此只區別在於templateName

有沒有在Ember.js中的方法,我可以說ForgotPassword繼承Login,然後只需將templateName設置爲forgotPassword

謝謝。

+1

順便說一句,在你的'didInsertElement' /'willDestroyElement',你只能直接操作DOM元素,這這種觀點的元素或後裔,當你這樣做時,使用'this。$()'。例如'這一點。$( '輸入[名稱=郵件]')'。 – 2013-05-13 02:45:08

回答

2

您可以簡單地從你剛剛創建的視圖擴展:

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