mardi 27 octobre 2015

emberjs - sorting data retrieved from Firebase

I've spent the last three days trying to figure this out and i hope someone from here could help.

Note regarding setup: I'm working off Ember-Cli therefore my Ember version 1.13.7 and Ember-Data 1.13.8

To learn more about how emberJS works i decided to create a simple blog system that i will use on my own website. The data is loaded from a Firebase database using the Emberfire plugin.

Help: I cannot sort the data i retrieve into a descending order. For example, if i have 5 posts created on Monday, Tues, Wednesday, Thursday and Friday. Each with a unique timestamp in numerical order.

When i retrieve data it shows in this order:

1st ever post (oldest)
2nd ever post
3rd ever post
4th ever post
5th ever post (newest)

i want to reverse the order so my latest blog post appears on top.

I am retrieving data with the following code:

return this.store.find('post');

I can't work out how to use: sortBy which is from Ember itself or the orderBy() which is from firebase/emberfire?

I understand it needs to be inside a controller which will modify the data from the model before presenting it in the view. But can anyone help?

heres some more code:

Attempt at a controller - it doesn't work:

import Ember from 'ember';

 export default Ember.ArrayController.extend({
    sortedModel : function(){
        return this.get('model').sortBy();
    }.property('@each')
});

View Template:

{{#each sortedModel as |post|}}
    {{#blog-post post=post}}{{/blog-post}}
{{/each}}

{{outlet}}




Aucun commentaire:

Enregistrer un commentaire