Hi everyone! I have only been working with ember and ember-data for about a week now, so please bear with me if this question is really silly.
I’ve been trying to implement a feature where the user can click a button to load more images. So, when the page first loads, only the first 10 images are displayed. The user clicks a “Load More” button, and 10 more are displayed, etc. But I am really stuck right now. I’ve spent the evening searching for solutions, but I can’t figure out what to do for the life of me.
So, my route’s initial model is fairly straightforward. I have just put random dummy data into the parameters list for brevity:
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('event', {page: 1, perPage: 10, lat: 2, lng: 2});
}
})
(Just to note: the query is dependent on the user’s location. I’m just pointing this out because I recall reading that sending parameters to the store’s find query affects the way the results are processed.)
I am able to get this data to load on the page no problem. The issue is when the user wants to load more images. In my controller, I have a “loadMore” action where I simply just increment the page by one and call find on the store again.
loadMore: function() {
// Increment page
//
this.store.find('image', {page: page + 1, perPage: 10, lat: 2, lng: 2})
}
Now, from my understanding, since these queries are using extra parameters, the model won’t automatically be updated with the new records, whereas if they were omitted, the model would reflect the changes. But since I can’t remove those parameters, how would I then add these additional records to my model? I tried doing it manually after the promise was resolved… so something like this:
var self = this;
var more = this.store.find('image', {page: page + 1, perPage: 10, lat: 2, lng: 2});
more.then(function() {
self.pushObjects(more);
});
But this didn’t work. It threw an error because the model’s array is immutable.
I really hope this is making sense. I’m still learning everything, so it’s entirely possible that I am way off base here. Any help on how to resolve this would be greatly appreciated. I don’t even know if this is the best/correct approach, so any alternative suggestions are also happily welcome.
Thank you for your time.
Mike