4

ApplicationController に検索プロパティがあり、検索の入力フィールドにリンクされています。ProjectControllerでApplicationControllerの検索フィールドにアクセスしたい。同期する必要があります。次のコードを使用しますが、機能しません。

/ app/controllers/projects/index.js (プロジェクト コントローラー)

import Ember from 'ember';
export default Ember.Controller.extend({
    needs: ['application'],
    searchBinding: 'controllers.application.search'
});

/ app/controllers/application.js (アプリケーション コントローラー)

  import Ember from 'ember';
    export default Ember.Controller.extend({
      search: ''
    )}

アプリケーション.hbs

{{input value = search}}

4

3 に答える 3

15

Ember needs は廃止され、現在は別の方法で使用されています。

それはこのように動作します:

applicationController: Ember.inject.controller('application'),
mySearch: Ember.computed.alias('applicationController.search')

あなたの hbs テンプレートで -

{{mySearch}}

 アプリケーションのプロパティ「検索」と同期しています。

于 2016-05-20T11:00:42.290 に答える
6

注入することで、コントローラー内の任意のコントローラーにアクセスできます。

import Ember from 'ember';
export default Ember.Controller.extend({
    applicationController: Ember.inject.controller('application'),
    searchProperty: Ember.computed.alias('applicationController.search'),
)};

Ember コントローラ間の依存関係の管理

于 2016-05-20T11:02:15.973 に答える