我试图重复嵌套对象属性并对它们进行排序,但排序对我不起作用.
我见过这个:
How to orderby in AngularJS using Nested property
但是json结构是不同的,我无法让它工作.
我的代码:
@H_301_11@<div ng-repeat="item in data | orderBy:order.allListPosition"> <div>{{item.name}} - {{item.order}}</div> </div>范围:
@H_301_11@$scope.data = { "78962": { "id": "78962","name": "item 2","type": "blind","order": { "allListPosition": "008","catListPosition": "059" },"data": { "status": "stop","percent": 20 },"longPress": { "item": "78966","active": true } },"78963": { "id": "78963","name": "item 3","type": "coolmaster","order": { "allListPosition": "053","catListPosition": "001" },"data": { "status": 1,"temp": 16,"point": 25,"mode": "cool","fan": 3 },"longPress": { "item": "78966","active": false } } };任何人都可以告诉我我做错了什么?
非常感谢
阿维
解决方法
orderBy在这里不起作用有两个原因:
> orderBy仅适用于数组,但您将它应用于普通对象.
>要按表达式排序,您需要使用表达式为orderBy赋予字符串值.你给它order.allListPosition,它等于$scope.order.allListPosition(它不存在).
要解决第二个问题(并从上面合并dataArray):
@H_301_11@<div ng-repeat="item in dataArray | orderBy:'order.allListPosition'">