2014-03-13 79 views
0

我有作爲應用路線('/')內限定的/newLicense路線:如何在EmberJS的子模板中使用父模板的屬性?

App.Router.map(function() { 
    this.route('newLicense', {path: '/newLicense'}); 
}); 

我有稱爲is_admin它獲取適當地設定每個應用控制器被調用時應用控制器的特性。現在在newLicense模板中,我想根據登錄用戶是否爲admin(它存儲在應用程序控制器的is_admin中)顯示一條消息。

我試圖

{{#if is_admin}} 
    <p> You are logged in as Admin user. </p> 
{{else}} 
    <p> You are logged in as Read-Only user. </p> 
{{/if}} 

但它不工作。我也試圖在newLicenseController提供應用程序控制器:

App.newLicenseController = Ember.ObjectController.extend({ 
    needs: ['application'], 
}); 

但它仍然沒有工作。然後我嘗試{{#if application.is_admin}}仍然沒有運氣。

對這個概念的任何幫助非常感謝。謝謝。

回答

1

明白了。這是一個簡單的錯誤。應該訪問需求中列出的控制器的屬性,如下所示:{{controllers.controller_name.property_name}}。

所以在這種情況下,它會變成:

{{#if controllers.application.is_admin}} 
    <p> You are logged in as Admin user. </p> 
{{else}} 
    <p> You are logged in as Read-Only user. </p> 
{{/if}}