Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting an array in a component

I'm trying to pass results into a component and then have the component sort it:

// data passed to component
{
    type: 'people',
    res : [
      {name: 'charlie', age: '55'},
      {name: 'bobby', age: '19'},
      {name: 'raymond', age: '39'}
    ]
}

// component
App.ShowResultsComponent = Ember.Component.extend({

    // note sure how to set up array controller
    sorted : Ember.ArrayProxy.create({
        content : this.get('results.res')
    }),

)}

my jsbin

I'm not sure if I'm missing/misunderstanding some fundamental, but is it possible to include an array controller as a property in a component? Any clarification would be appreciated.

like image 914
cat-t Avatar asked Dec 11 '22 03:12

cat-t


1 Answers

You can also extend the component with Ember.SortableMixin, then use arrangedContent as you normally would in a controller.

  App.ShowResultsComponent = Ember.Component.extend(Ember.SortableMixin, {

    ...

  });

Here is your JSBin updated for Ember 1.9.1 and using the Sortable Mixin

like image 73
patmood Avatar answered Jan 04 '23 17:01

patmood