everett1992
everett1992

Reputation: 2671

Ember: Set controller properties from {{ render }} helper

I have a simple ember controller which displays a list of strings and has a search box.

App.SearchController = Ember.ArrayController.extend
  query: undefined
  queried: (->
    this.get('model').filter (object) -> object.match(query)
  ).property('model', 'query')

This controller/template is only rendered within other templates. I want to render the controller with a default query like so

# titles = ['abc', 'def', 'ghi']
{{ render 'search' titles query='abc'}}

The above syntax doesn't work, is what I want to do possible?

Upvotes: 1

Views: 507

Answers (1)

ppcano
ppcano

Reputation: 2861

I would create a component in this case:

SearchBoxComponent = Em.Component.extend({
  query: undefined
  queried: (->
    this.get('titles').filter (object) -> object.match(query)
  ).property('titles', 'query')
}});


{{search-box titles=titles query='abc'}}

// components/search-box.handlebars
{{#each item in queried}}
   {{item}}
{{/each}}

Upvotes: 2

Related Questions