I have a table to indicate results of certain teams, each team has two values - PTS (points) and GD (goal difference).
Data looks something like this:
A: PTS=3, GD=+3,
B: PTS=2, GD=+1,
C: PTS=2, GD=-1,
D: PTS=0, GD=-1
I want display them via ng-repeat, in order of PTS first and foremost (as above). But if any team is equal with another on points, it will need to be decided by GD (goal difference). Finally if even this another sort them, I want it to fall back to alphabetical ordering.
I know how to use orderBy, and then can just use the teamName
propery (A, B, C) etc. to order them.
I am guessing it is something like creating a custom orderBy filter something like this:
orderBy="{{pts || gd || teamName}}"
I'm not sure of the syntax though, or where to put this code. Can I attach the above logic to one variable and then call that in orderBy? Or is it a filter?
Any help with this would be appreciated.
答案 0 :(得分:0)
要将orderBy与多个字段一起使用,您必须在数组中添加此字段,如['pst','gd','teamName']
现在数据是:
A: PTS=3, GD=+3,
B: PTS=2, GD=+1,
C: PTS=2, GD=-1,
D: PTS=0, GD=-1
如果考虑“A”,“B”,“C”和& “D”是团队名称。
然后orderBy语法是:
orderBy:['-pst', 'gd', 'teamName']
***“ - pst”用于按降序显示pst元素