「アプリケーション」コンテキストに配置したナビゲーションバーを持つアプリケーションがあります。デフォルトでは、これらのナビゲーションバーのリンクは無効になり、テンプレートからの特定のアクションでのみ有効になります。他のコントローラからコントローラーのプロパティを変更します
ナビゲーションバー内のリンクの無効状態が含まれているアプリケーションコントローラ: -
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}}
{{outlet}} </script>
<button {{action 'handleToggle'}}>Toggle Application Menu </button>
インデックス・テンプレート
<script type="text/x-handlebars" id="index"> <button {{action 'toggleApplicationButton'}}>Toggle Application Menu </button> </script>
私は "トグルアプリケーションメニュー" ボタンをクリックすると、私は、コンソールで次の出力を取得します。
しかし、エンバーインスペクタでプロパティが変更されません "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*/
}
}
});
ためEmberjs official documentationを参照してください使用することができますルート
で使用することができます。 inject.controller()の問題は同じです。私は変数がコンソールで変わるのを見ることができます。しかし、** Emberのインスペクタでは、変数は同じまま**、リンクはまだ無効です。これはEmberのバグですか? –