@kitsunde wrote:
I wrote some really awkward code earlier which basically filters through each item in the recordset on some condition and then selects the edge one.
export default Ember.Route.extend({ model(params){ const stories = this.store.findAll('story'); const story = this.store.findRecord('story', params.id); const nextStory = story.then(function(story){ const laterStories = stories.filter(function(filterStory){ return filterStory.get('number') > story.get('number'); }); if(laterStories.get('firstObject')){ return laterStories.get('firstObject'); }else{ return stories.get('firstObject'); } }); const previousStory = story.then(function(story){ const newerStories = stories.filter(function(filterStory){ return filterStory.get('number') < story.get('number'); }); if(newerStories.get('lastObject')){ return newerStories.get('lastObject'); }else{ return stories.get('lastObject'); } }); return Ember.RSVP.hash({ story, nextStory, previousStory }); } });
I know, it looks awful, there must be a nicer way of doing that. Any suggestions?
Posts: 2
Participants: 2