2016-03-30 8 views
1

「アプリケーション」コンテキストに配置したナビゲーションバーを持つアプリケーションがあります。デフォルトでは、これらのナビゲーションバーのリンクは無効になり、テンプレートからの特定のアクションでのみ有効になります。他のコントローラからコントローラーのプロパティを変更します

ナビゲーションバー内のリンクの無効状態が含まれているアプリケーションコントローラ: -

App.ApplicationController = Ember.Controller.extend({ 
userName:"TestUser", 
firstLinkDisabled:true, 
actions:{ 
    handleToggle:function(){ 
     console.log("Handling application action with linkstatus="+this.firstLinkDisabled); 
     //this.set("firstLinkDisabled",false); 
     this.toggleProperty("firstLinkDisabled"); 
    } 
} 

})

アプリケーションコントローラにアクションを送信しますインデックスコントローラー: -

App.IndexController = Ember.Controller.extend({ 
actions:{ 
    toggleApplicationButton:function(){ 
     this.controllerFor("Application").send("handleToggle"); 
    } 
} 

})

アプリケーションテンプレート:

 

    <script type="text/x-handlebars"> 
    

{{#link-to 'first' disabled=firstLinkDisabled}}First link in application{{/link-to}}
<button {{action 'handleToggle'}}>Toggle Application Menu </button>

{{outlet}} </script>

インデックス・テンプレート

 

<script type="text/x-handlebars" id="index"> 
<button {{action 'toggleApplicationButton'}}>Toggle Application Menu </button> 
</script> 

私は "トグルアプリケーションメニュー" ボタンをクリックすると、私は、コンソールで次の出力を取得します。

Console Output

しかし、エンバーインスペクタでプロパティが変更されません "firstLinkDisabled"。 Ember Inspectorの画像: - Ember Inspector Image

リンクは無効のままです。

私はここで間違っていますか?
emberは他のコントローラのプロパティを変更できませんか?
このようにするにはどうすればいいですか?そして、あなたがプロパティにアクセスすることができ、インデックスコントローラ

//index.js 
application: Ember.inject.controller(), 

にアプリケーションコントローラを注入し、

import Ember from 'ember'; 

export default Ember.Controller.extend({ 
    /*first, inject a controller*/ 
    loginController: Ember.inject.controller('lang.login'), 
    /*some code*/ 

    actions: { 
    register: function() { 
     /*some code*/ 
     /*work with injected controller*/ 
     var c = this.get('loginController'); 
     c.set('identification', that.get('user').email); 
     c.set('password', that.get('user').plainPassword); 
     /*some code*/ 
    } 
    } 
}); 

ember docs

+0

ためEmberjs official documentationを参照してください使用することができますルート

で使用することができます。 inject.controller()の問題は同じです。私は変数がコンソールで変わるのを見ることができます。しかし、** Emberのインスペクタでは、変数は同じまま**、リンクはまだ無効です。これはEmberのバグですか? –

答えて

1

は私のプロジェクトからの簡単な例です。このようなアプリケーションコントローラ:

//index.js 
application.toggleProperty("firstLinkDisabled"); 
1

使用Ember.inject.controller()

App.IndexController = Ember.Controller.extend({ 
    appController: Ember.inject.controller("Application"), 
    actions:{ 
    toggleApplicationButton:function(){ 
     this.get("appController").send('handleToggle'); 
    } 
    } 
}) 

controllerForまた、あなたはalias

appController: Ember.computed.alias('controllers.Application') 

がさえエンバーを使用した後に、詳細

関連する問題