我有数据:
{
games":[
{
"id":"AAA",
"categories":["1"],
"name":"Joker Double Up"
},
{
"id":"BBB",
"categories":["1"],
"name":"Joker Wild Up"
},
{
"id":"CCC",
"categories":["3"],
"name":"Joker Wild Double Up"
},
{
"id":"DDD",
"categories":["2"],
"name":"Wild Double Up"
},
{
"id":"EEE",
"categories":["2"],
"name":"Joker Wild Double"
}
]
}
(它来自后端,所以我不能在这里编辑)
在这里用ng-repeat显示它:
<div ng-repeat="(key, value) in gamesList | groupBy: 'categories' "> ...
</div>
我按照“类别”将每个群组的游戏分组,现在想要订购这些群组。 (我使用角度1.6也是角度滤波器)
我希望像这样通过“id”订购这些数据
1. CCC
2. AAA
3. BBB
4. EEE
5. DDD
(它对js orderBy没有任何逻辑陈述,只是自定义顺序)
我知道我无法为orderBy函数找到一些参数,因为它已经是自定义顺序。我怎么能意识到这一点?
答案 0 :(得分:0)
如果您希望程序对项目进行排序,则必须提供排序依据的逻辑条件。一个简单的解决方案可以是为您的项添加索引属性,并将其用于Angular的orderBy
函数。
{
games":[
{
"id":"AAA",
"categories":["1"],
"name":"Joker Double Up",
"index": 2
},
{
"id":"BBB",
"categories":["1"],
"name":"Joker Wild Up",
"index": 3
},
{
"id":"CCC",
"categories":["3"],
"name":"Joker Wild Double Up",
"index": 0
},
{
"id":"DDD",
"categories":["2"],
"name":"Wild Double Up",
"index": 5
},
{
"id":"EEE",
"categories":["2"],
"name":"Joker Wild Double",
"index": 4
}
]
}