私は次の問題に遭遇しました:私はコントローラーを持っていて、次のようなモデルをフィルタリングしたいです:
App.ProductsController = Ember.ArrayController.extend({
itemController: 'product',
filteredContent: function(query) {
var query = this.get('query')
var products = this.get('content').filter(function(item) {
return true // Condition goes here
})
return products
}.property('query')
})
私の見解では、これはうまく機能しています:
{{#each product in filteredContent}}
...
<h1>{{product.name}}</h1>
...
<button {{action addToCart}}>Add to cart</button>
{{/each}}
少なくともループする限り。アクションaddToCartが機能せずNothing handled the event 'addToCart'、ボタンを押すとエラーが発生します。で定義されていますが、ProductController.
ここで興味深い部分があります。フィルタリングされた結果を使用しない場合、each product in controller私の見解では、addToCartクリックは機能しています。ビューとコントローラーの関係について、私が理解していないことがあると思いますので、助けていただければ幸いです。
ありがとう!