javascript – AngularJs ng-repeat orderBy不适用于嵌套对象属性

我试图重复嵌套对象属性并对它们进行排序,但排序对我不起作用.

我见过这个:
How to orderby in AngularJS using Nested property

但是json结构是不同的,我无法让它工作.

Plunker

我的代码

<div ng-repeat="item in data | orderBy:order.allListPosition">
       <div>{{item.name}} - {{item.order}}</div>
   </div>

范围:

$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(它不存在).

解决一个问题,请添加数据对象的数组:

$scope.dataArray = Object.keys($scope.data)
  .map(function(key) {
    return $scope.data[key];
  });

解决第二个问题(并从上面合并dataArray):

<div ng-repeat="item in dataArray | orderBy:'order.allListPosition'">

http://plnkr.co/edit/BXgYPTElSM3sjvLg30CL?p=preview

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...