vendredi 31 juillet 2015

Ember CLI Array Controller not sorting through each loop

I can't get sortAttribute to work from an ArrayController. I think it's because the ArrayController can't access the model.

The posts resource defined in app/router.js:

export default Router.map(function() {
  this.resource('posts', function() { 
    this.route('index', {path: '/'});
    this.route('new');
    this.route('full', {path: '/:id'});
});
 

My model for a single post (models/post.js)

export default DS.Model.extend({
  title: DS.attr('string'),     
  category: DS.attr('string'),          
  created_at: DS.attr('date'),  
  
)}

My template displays the list of posts using an {{#each}} helper
(templates/posts/index.hbs):

The inner contents of the each helper is contained in a component named 'blog-list'.

{{#each model as |post|}}
  {{blog-list model=post}}
{{/each}}

The list of posts displays fine.

I have added code to sort the list by the title property (controllers/posts/index.js):

export default Ember.ArrayController.extend({
  sortProperties: ['title'],
  sortAscending: true,
});

I'm not sure why, but the title column is not being sorted.




Aucun commentaire:

Enregistrer un commentaire