Reputation: 162
I'm new to this EmberJS environment and I would to like ask, how do you send parameters to controller functions? I would simply like to filter the model I'm getting. but I don't know how to pass an argument onto the controller. could someone tell me how? any comments/suggestions would be greatly appreciated
Html file:
<script type="text/x-handlebars" data-template-name="favorite/items">
<ul>
{{#each i in "filteredItems" }}
<li>{{i.name}}</li>
{{/each}}
</ul>
</script>
JS file:
App.FavoriteItemsController = Ember.ArrayController.extend({
filteredItems: function (id) {
return this.get('model').filterProperty('favoriteId',id);
}.property('[email protected]')
});
Upvotes: 1
Views: 53
Reputation: 47367
Handlebars is logic-less and you don't pass properties into a computed property. The trick is to make the computed property depend on another property that can change altering your computed property.
<script type="text/x-handlebars" data-template-name="favorite/items">
<ul>
{{#each i in filteredItems }}
<li>{{i.name}}</li>
{{/each}}
</ul>
</script>
JS file:
App.FavoriteItemsController = Ember.ArrayController.extend({
filteredParam: 1,
filteredItems: function () {
var filteredParam = this.get('filteredParam');
return this.get('model').filterBy('favoriteId',filteredParam);
}.property('@each.favoriteId', 'filteredParam')
});
As you change filteredParam
ember will consider filteredItems
as dirty, and recompute it.
Example: http://emberjs.jsbin.com/meruli/edit?html,js,output
Upvotes: 1