Skip ng-repeat JSON ordering in Angular JS

后端 未结 4 1728
难免孤独
难免孤独 2020-11-30 06:02

Does anybody know how I can SKIP JSON ordering altogether when I use ng-repeat (in a painless way probably)?

For example, my source JSON looks somet

4条回答
  •  一个人的身影
    2020-11-30 06:42

    At the moment there is no elegant way to do this. Reason being that - ngRepeat creates an associative array, which is called and not the JSON itself. Although the ECMAScript Standard mentions that:

    The declaration order of object properties must be preserved, and iteration must happen in the same order.

    But somehow, Angular guys overlooked it. This might get rectified in the later releases.

    I still think Angular's behaviour makes more sense. As objects often have more initialisation logic around them than arrays, I think it's fair to assume that the order often might not be what the user actually wants/expected, so forcing a specific sorting ensure the proper behaviour - especially when we also have to deal with older browsers.

提交回复
热议问题