1

I have collection like this:

child{length:3, models:array[3], _byId:Object}

I wanna sort models array, I use lodash like this:

var array_of_objects = new ListCollection();

var data = _.sortByOrder(array_of_objects.models, ['id'], ['asc']);

And I get result only:

[child, child, child]

How to sort models arrays with keep length and the Object.

Wahyu Kodar
  • 654
  • 1
  • 6
  • 15

1 Answers1

0

If you want to order the original collection, set collection.comparator to 'id' and then call collection.sort().

To order the models without affecting the collection do: _.sortBy(collection.models, 'id')

Note that these will order the Models, not native js arrays. If your looking to operate on a raw collection of arrays, get a copy of the collection with var models = JSON.parse(collection.toJSON()) and then follow the instructions for _.sortBy.

Mbrevda
  • 2,888
  • 2
  • 27
  • 35