Is there a way to sort/order keys in JavaScript objects?

后端 未结 7 2177
故里飘歌
故里飘歌 2020-11-28 08:16

For example the following

var data = {
    \'States\': [\'NSW\', \'VIC\'],
    \'Countries\': [\'GBR\', \'AUS\'],
    \'Capitals\': [\'SYD\', \'MEL\']
}
for          


        
7条回答
  •  隐瞒了意图╮
    2020-11-28 08:55

    If conversion to an array does not suit your template and you know the keys of your object you can also do something like this:

    In your controller define an array with the keys in the correct order:

    this.displayOrder = [
        'firstKey',
        'secondKey',
        'thirdKey'
    ];
    

    In your template repeat the keys of your displayOrder and then use ng-init to reference back to your object.

    {{ entry.detail }}

提交回复
热议问题