Stop AngularJS ng-repeat rendering in alphabetical order

后端 未结 3 760
抹茶落季
抹茶落季 2021-01-12 20:19

In my angular app I\'m trying to display JSON data in a table. The data looks like this:

$scope.data = 
  {
    \"EVENT NAME\":\"Free Event\",
    \"ORDER ID         


        
3条回答
  •  没有蜡笔的小新
    2021-01-12 20:59

    A Javascript object does not have the concept of 'natural order' of its keys:

    Definition of an Object from ECMAScript Third Edition (here):

    4.3.3 Object An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function [...]

    You probably should change a bit your data structure...
    For example:

    $scope.data = 
    {
        1: { "EVENT NAME": "Free Event" },
        2: { "ORDER ID": 311575707 },
        /* ... */
    };
    

    And then use the numerical key to sort your items...

提交回复
热议问题