0

来自 jquery 的响应已损坏

不知何故,response.data.pool.accountassoc 数组是按键排序的?!

jQuery

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

代码

var success = function(response){
    console.log(response.data.pool.account);
};

控制台中的响应(萤火虫)

{"data":{"pool":{"account":{"176":{"account_id_":"999"},"169":{"account_id_":"1110"},"189":{"account_id_":"1120"},"190":{"account_id_":"1130"},"173":{"account_id_":"2100"},"188":{"account_id_":"2200"},"184":{"account_id_":"3010"},"185":{"account_id_":"3020"},"186":{"account_id_":"4010"},"187":{"account_id_":"4020"},"179":{"account_id_":"5000"},"181":{"account_id_":"9999"},"167":{"account_id_":"14261"},"168":{"account_id_":"14262"},"172":{"account_id_":"15000"},"171":{"account_id_":"15261"},"170":{"account_id_":"15262"},"177":{"account_id_":"15500"},"174":{"account_id_":"16000"},"182":{"account_id_":"16500"},"175":{"account_id_":"17000"},"183":{"account_id_":"17500"},"180":{"account_id_":"19999"}}}}}

jquery成功方法中的控制台输出

167
    Object { account_id_=14261}
168
    Object { account_id_=14262}
169
    Object { account_id_=1110}
170
    Object { account_id_=15262}
171
    Object { account_id_=15261}
172
    Object { account_id_=15000}
173
    Object { account_id_=2100}
174
    Object { account_id_=16000}
175
    Object { account_id_=17000}
176
    Object { account_id_=999}
177
    Object { account_id_=15500}
179
    Object { account_id_=5000}
180
    Object { account_id_=19999}
181
    Object { account_id_=9999}
182
    Object { account_id_=16500}
183
    Object { account_id_=17500}
184
    Object { account_id_=3010}
185
    Object { account_id_=3020}
186
    Object { account_id_=4010}
187
    Object { account_id_=4020}
188
    Object { account_id_=2200}
189
    Object { account_id_=1120}
190
    Object { account_id_=1130}
4

1 回答 1

2

Javascript 对象不保证其键的任何特定顺序。

由 js 引擎根据需要在内存中布局属性。

如果您的代码依赖于键的顺序 - 您需要从现在开始停止它(例如,使用数组)。

于 2013-06-02T10:01:43.923 回答