1

Ember.RouterまたはEmber.StateManagerを使用せずに、1.0より前のemberjsに対して書かれたコードベースがあります。可能であれば、反復的に Ember.Router に移行しようとしています。

スケルトンの App.ApplicationController、App.ApplicationView、および App.Router を作成しました (ルートは 1 つだけ)。App.ApplicationView は、既存のエントリ ポイント ビューである App.PreRouterMainView をラップするだけです。既存のビューの {{action}} バインディングが機能しなくなったことを除いて、すべて正常に読み込まれました:

{{action "someTargetMethod"}}を呼び出すためによく使用しますPreRouterChildView.someTargetMethod()が、PreRouterMainView を埋め込み/「ルーティング」した後、代わりにルーターで someTargetMethod() が呼び出されるようになりました。

PreRouterMainView と子ビューを引き続き「古い方法」で動作させ、イベントがルーターではなく最も近いビューでメソッドを呼び出す簡単な方法はありますか?

それとも、1 つの大きな変更ですべてのビュー メソッドをルーター メソッドにリファクタリングする必要がありますか? 可能であれば、これを繰り返したいと思います。

4

1 に答える 1

4

ビュー (または有効なパス上の他のオブジェクト) を明示的に対象とするように、アクションをリファクタリングする必要があります。

{{action someTargetMethod target="view"}}

ただし、ルーターはほとんどのアクション、特に状態/ルートを変更するアクションを処理する必要があるため、アクションのデフォルト コンテキストはルーターに変更されました。アクションを処理するルーター メソッドで、(イベント コンテキストを介して) コントローラーとビューのメソッドを呼び出すことができます。アクションが状態やデータを変更しない場合は、ビュー ハンドルを使用しても問題ありません。

編集:インラインコードのドキュメントは、コントローラーにプロパティを設定することでデフォルトのアクションターゲットを変更できることを示しています:

### Specifying a Target
There are several possible target objects for `{{action}}` helpers:

In a typical `Ember.Router`-backed Application where views are managed
through use of the `{{outlet}}` helper, actions will be forwarded to the
current state of the Applications's Router. See Ember.Router 'Responding
to User-initiated Events' for more information.

If you manaully set the `target` property on the controller of a template's
`Ember.View` instance, the specifed `controller.target` will become the target
for any actions. Likely custom values for a controller's `target` are the
controller itself or a StateManager other than the Application's Router.

If the templates's view lacks a controller property the view itself is the target.
于 2012-08-30T19:27:33.680 に答える