angularjs - Complex ng-repeat orderBy -


[{"score":"0.995074","content":"video games"},{"score":"0.950704","content":"media"},{"score":"0.916667","content":"arts & entertainment"}]

with above data available on each single ng-repeat item, able sort score "content":"video games". how can this?

edit clarification:

item 1

{ property1: value1, property2: value2, ..., scores: [{"score":"0.9","content":"video games"},{"score":"0.8","content":"media"},{"score":"0.7","content":"arts & entertainment"}] }

item 2

{ property1: value1, property2: value2, ..., scores: [{"score":"0.7","content":"video games"},{"score":"0.8","content":"media"},{"score":"0.9","content":"arts & entertainment"}] }

item 3

{ property1: value1, property2: value2, ..., scores: [{"score":"0.8","content":"video games"},{"score":"0.7","content":"media"},{"score":"0.9","content":"arts & entertainment"}] }

the above how data looks like. need ng-repeat sort these to: item 1, item 3, item 2 (descending) or item 2, item 3, item 1 (ascending).

i suppose "the above data available on each single ng-repeat item" mean each item has property scores data in form value. is, items following:

{   property1: value1,   property2: value2,   ...,   scores: [{"score": "0.995074", "content": "video games"}, ...] } 

then can use "getter function" feature of orderby. first prepare following function in scope:

$scope.videogamesscore = function (item) {   (var in item.scores) {     var rec = item.scores[i];     if (rec["content"] == "video games")       return rec["score"];   } } 

with function can write ng-repeat this:

ng-repeat="item in items | orderby:videogamesscore" 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -