如何通过Index ASC阻止Chrome和Opera对JSON对象进行排序? [英] How do you stop Chrome and Opera sorting JSON objects by Index ASC?

查看:121
本文介绍了如何通过Index ASC阻止Chrome和Opera对JSON对象进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



<$>使用ajax我发送了一个正确形成的JSON对象:

<$ $ {
type:POST,
url:SITE_URL +'/ data.php',
dataType:json,
data:{ajax:1},
success:function(data){
console.log(data);
}
});

然而,Opera和Chrome虽然接收到相同的对象,却以错误的顺序打印出对象,看起来他们都是通过身份证号码进行排序,而不是一个人留下来!



有没有办法阻止这种自动排序?



编辑后,发现它是按索引号排序我认为最好的方法可能是不使用索引来存储object_id,而是存储我想要命令的id号object by。



然而,我仍然想知道是否有办法阻止排序。



谢谢

Edit2,我只想指出,我将以另一种方式来做这件事,因为我觉得我在滥用对象用这种方法。不过,我仍然想明白为什么Opera和Chrome会觉得这是他们改变对象ID顺序的权利:



问题是我试图保存处理权力,可以说我们有身份证的人,

<1> 1.John,2.Frank和3.Sally。然而,这些人中的每一个人都有一个很高的属性集(和其他东西)。 1.John.180,2 .Frank.220,3.Sally.150。为了节省处理时间,我要求人们按照它们的高度进行排序,结果我得到了一个2,1和3的数组以及其他属性。我将这个数组JSON并发送给浏览器。

现在FF会保留新订单
People [1]仍然是John,但在一个For n作为人员循环,他们会失灵。



如果我无法解决这个问题,我只需要不必在SQL阶段进行排序并添加额外的在JS阶段中循环和排序到一个数组中,尽管我希望避免对浏览器造成更多的压力,因为它已经是一个Js沉重的页面。



非常感谢

解决方案

不同的浏览器以不同的方式处理对象,我的错在于尝试使用构建对象的顺序作为参考。

I've got a problem.

Using ajax I sent a correctly formed JSON object using:

            $.ajax({
                type: "POST", 
                url: SITE_URL+'/data.php',
                dataType: "json",
                data: { ajax: 1 },
                success: function(data) {
                    console.log(data);
                }
            });

However, Opera and Chrome, although receiving the same object, print out the object in an incorrect order, it seems like they both perform a sort by ID number instead of just leaving it alone!

Is there a way to stop this auto sort?

Edit, after finding out it is a sort by index number I'm thinking the best method might be to not use the index for storing the object_id and instead store the id number which I want to order the object by.

However I would still like to know if there is a way to stop the sort.

Thank you

Edit2, I'll just like to note that I'm going to work on a different way of doing this, as I feel like I'm abusing objects with this method. However I'd still like to understand why Opera and Chrome feel it is their right to change the order of my objects IDs:

The problem would be me trying to save processing power, lets say we have people with an ID,

1.John, 2.Frank and 3.Sally. However each of these people have a hight property set (and other things). 1.John.180, 2.Frank.220, 3.Sally.150. To save on processing, my I request the result of people be sorted by their height so I get an array of 2, 1, 3 with their other properties. I JSON this array and send it to the browser.

Now FF will keep the new order People[1] would still be John but in a For n as person loop they'll be out of order.

If I can't get around this I'll just have to not bother sorting at the SQL stage and add extra looping and sorting into an array in the JS stage although I wanted to avoid more stress on the browser as its already a Js heavy page.

Many thanks

解决方案

Different browsers handle objects in different ways, my fault was to try and use the order I built an object as a reference where I shouldn't.

这篇关于如何通过Index ASC阻止Chrome和Opera对JSON对象进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆