You can structure your router like this:
App.Router.map(function() {
this.resource('items', {path: '/items'}, function(){
this.route('bucket', {path: '/:bucket'});
this.route('tag', {path: '/tag/:tag'});
});
});
This shows all Item
s at #/items
and filters by bucket at #/items/bucketNameHere
and by tags at #/items/tag/tagNameHere
.
If all items are displayed in the ItemRoute
:
App.ItemsRoute = Ember.Route.extend({
model: function(){
return this.store.find('item');
}
});
Then you can handle the filtering in the ItemsBucketRoute
and ItemsTagRoute
:
App.ItemsBucketRoute = Ember.Route.extend({
model: function(params){
console.log("model fired");
return this.modelFor('items').filterProperty('bucket', params.bucket);
}
});
App.ItemsTagRoute = Ember.Route.extend({
model: function(params){
return this.modelFor('items').filterProperty('tag', params.tag);
}
});
You can also accomplish list filtering using the filterProperty
of arrayController
s.