AngularJS orderBy属性不正确

时间:2018-09-23 01:30:47

标签: angularjs angularjs-orderby

我正在遍历对象的数组,希望它们按'ecuName'属性按字母顺序排序。我不明白为什么在“ ABC”之前渲染“ HVAC”。

    "ecuInfoList": [
      {
        "id": 4,
        "ecuName": "ACC"
      },
      {
        "id": 6,
        "ecuName": "HVAC"
      },
      {
        "id": 5,
        "ecuName": "ABG"
      }
    ]

编辑

忘记添加模板代码。

<div ng-repeat="ecu in config.ecuInfoList | orderBy:'ecuName' track by $index"><strong>{{ ecu.ecuName }}</strong>...

enter image description here

1 个答案:

答案 0 :(得分:1)

您现在可以使用ng-repeat正确访问阵列。检查工作的演示版

演示

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
 $scope.data = { "ecuInfoList": [
      {
        "id": 4,
        "ecuName": "ACC"
      },
      {
        "id": 6,
        "ecuName": "HVAC"
      },
      {
        "id": 5,
        "ecuName": "ABG"
      }
    ]
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
 <div ng-repeat="mydata in data.ecuInfoList | orderBy:'ecuName'">
   {{mydata.ecuName}}
 </div>
</body>