mardi 24 février 2015

ember static filter with query params

I have a list of posts and I need filter by social_network, I'm using query params to filter, my question is how temporary filter the model so that later I can come back to show all


route posts.index with:



model(params) {
return this.store.find('post');
}


and also a controller for it:



export default Ember.ArrayController.extend({
queryParams: ['social_network'],
social_network: 'all',

paramsDidChange: function() {
var network = this.get('social_network');
var posts = this.get('model');

if(network === 'all') {
return posts;
}
return posts.filterBy('social_network', network);
}.observes('social_network', 'model'),
});


view:



{{#each post in model}}
<li>
{{post-index post=post}}
</li>
{{/each}}




Aucun commentaire:

Enregistrer un commentaire