javascript - How do I sort my list of objects by an id array in angularjs? -


i'm trying sort list of arrays, no avail.

the problem: have list of objects need sort id string, inside array.

json:

[{"id":2613,"name":"aula 01","section":989},{"id":2614,"name":"aula 02","section":989},{"id":2616,"name":"aula 04","section":989},{"id":2617,"name":"aula 05","section":989,},{"id":2615,"name":"3 - aula 03","section":989}] 

array id sequence:

["2613", "2614", "2615", "2616", "2617"] 

how order ng-repeat or loop in array?

if need arbitrary order of given id sequence array, use object order sorting.

array = [{ id: 2613, name: "aula 01", section: 989 }, { id: 2614, name: "aula 02", section: 989 }, { id: 2616, name: "aula 04", section: 989 }, { id: 2617, name: "aula 05", section: 989 }, { id: 2615, name: "3 - aula 03", section: 989 }],      sequence = ["2617", "2613", "2614", "2615", "2616"],      order = {};    sequence.foreach(function (id, i) { order[id] = + 1 });    array.sort(function (a, b) { return order[a.id] - order[b.id]; });    console.log(array);
.as-console-wrapper { max-height: 100% !important; top: 0; }


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -