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
Post a Comment