1

I ran into the following problem: I've a controller and I want to filter the models, something like:

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')
})

Which is working fine in my view:

{{#each product in filteredContent}}
  ...
  <h1>{{product.name}}</h1>
  ...
  <button {{action addToCart}}>Add to cart</button>
{{/each}}

At least as far as looping. The action addToCart doesn't work and leads to the error Nothing handled the event 'addToCart' when hitting the button. Even though it's defined in the ProductController.

Now here is the interesting part: if I don't use the filtered results, but just each product in controller in my view, the addToCart click is working. I guess there's something about the relation between views and controllers I don't understand, so I appreciate any help.

Thanks!

4

1 回答 1

0

使用该{{#each item in items}}语法不会更改绑定范围。因此,您已绑定到product.name. 如果 addToCart 在 ProductController 而不是 ProductsController 中,您需要将您的操作绑定编写为action addToCart target="product".

于 2013-07-01T15:46:53.853 回答