ビューを作成したオブジェクトを配列にプッシュしようとしていますが、参照が何らかの形で失われています。が定義された Ember ビューがありますeventManager。
FrontLine.NewProductButton = Em.View.extend({
tagName: 'button',
classNames: ['addtl_product',],
templateName: 'product-button',
eventManager: Ember.Object.create({
click: function(event, view) {
FrontLine.ProductsController.toggleProductToCustomer(event, view);
}
})
})
そのビューは、ヘルパーProductsControllerを使用してオブジェクトから取得されるプロパティでレンダリングされる一連のボタンをレンダリングします。#eachその部分はうまく機能します。そして、これらのボタンのいずれかをクリックすると、クリック イベントが発生し、toggleProductToCustomerから指定したハンドラー関数 ( )を正常に呼び出すなど、私が要求したことはすべて実行されProductsControllerます。
FrontLine.ProductsController = Em.ArrayController.create({
content: [],
newProduct: function(productLiteral) {
this.pushObject(productLiteral);
},
toggleProductToCustomer: function(event, view){
FrontLine.CustomersController.currentCustomer.productSetAdditional.pushObject(view.context);
}
});
その関数を使用して、そのビューにデータが取り込まれたプロパティを持つオブジェクトを配列にプッシュしようとしています。私のアプリの別の場所 (単純な検索フィールド) は、pushObject(view.context). ただし、ここでは、配列にプッシュされるのはundefined. 代わりにview.templateContextを使用してみましたが、うまくいきません。viewこれらの関数内からボタンのオブジェクトを console.log-ing しようとすると、期待どおりの結果が得られます。
<(subclass of FrontLine.NewProductButton):ember623>
しかし、どちらかview.contextまたはview.templateContext戻りundefinedます。目的のオブジェクトにアクセスして、配列に追加するにはどうすればよいですか?