Jquery + Rails 4
<script>
var jsonData = {
"81404": "Object",
"81408": "Object",
"81416": "Object",
"80387": "Object",
"73952": "Object",
"74697": "Object",
"81411": "Object",
"74700": "Object"
};
console.log(jsonData);
</script>
Mozilla 输出(正确,符合预期)
Object { 81404="Object", 81408="Object", 81416="Object", 80387="Object", 73952="Object", 74697="Object", 81411="Object", 74700="Object"}
Chrome 输出(错误,???)
Object {73952: "Object", 74697: "Object", 74700: "Object", 80387: "Object", 81404: "Object", 81408: "Object", 81411: "Object", 81416: "Object"}
如何解决 Chrome 中的自动排序问题,任何建议帮助,,,
我正在使用此数据进行过滤,因为顺序很重要。
最佳答案
您的数据不是数组。它没有内在的秩序。它们只是对象的属性。
来自this Reference
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.
如果顺序很重要(或者只使用数组!),请将它们放在 JSON 对象的数组属性中。
例如像这样的东西:
var jsonData = {data: [
{"81404": "Object"},
{"81408": "Object"},
{"81416": "Object"},
{"80387": "Object"},
{"73952": "Object"},
{"74697": "Object"},
{"81411": "Object"},
{"74700": "Object"}]
};
console.log(jsonData);
或者只是列表
console.log(jsonData.data);
解释您正在对数据执行的操作会很有帮助,这样任何示例都更适用。
关于javascript - 如何停止 json 数据在 Google Chrome 中自动排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24241761/