Zach Shallbetter
Zach Shallbetter

Reputation: 1911

Filter a model within a range of IDs with Ember.JS

I have store that contains all of the images that the user has uploaded over time. When they upload a new group of images I receive each image's ID from the uploader. They are then moved to a new route where they need to update those newly uploaded images with meta data. I would like to use the previous store but filter out everything except the images they have uploaded.

So the question is... How do I filter a store by only a range of ids. For example, if my uploader returns [30, 31, 32]. I would like the view to only display those images.

I think the router should have a filter property like this but I'm not sure.

App.PhotosDetailsRoute = Ember.Route.extend( {
  model: function(params) {
     return this.get('content').filterBy('id', id >= params[0] );
  }
});

Any help would be appreciated.

Upvotes: 1

Views: 643

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

You'll want to use the filter function, I'm not positive what content is in this case, but this is how you use filter

model: function(params) {
  this.store.find('photos');
  return this.store.filter('photos', function(item){
    return item.get('id') >= 10; // dummy parameter
  });
}

Upvotes: 2

Related Questions