JS在IE和Safari没有工作多列排序 [英] js sorting by multiple columns not working in IE and Safari

查看:125
本文介绍了JS在IE和Safari没有工作多列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在<一个href=\"http://stackoverflow.com/questions/23933821/js-secondary-sort-by-different-column-depending-on-id-of-equal-column\">this 数据问题是,如果大部分等于它是由谁采摘水果时,两名工人在同一天的工作进行排序,大多数然后进行排序。如下所示

In this question the data is sorted by most then if most is equal it is sorted by who picked more fruit when the two workers worked on the same day. as shown below

    var workers = [
        {"id":"111","name":"April", "most":"7","sd-111222":"1","sd-111333":"2","sd-111444":"2","sd-111555":"2"},
        {"id":"222","name":"Bruno", "most":"7","sd-111222":"2","sd-222333":"1","sd-222444":"2","sd-222555":"2"},
        {"id":"333","name":"Carlos","most":"6","sd-111333":"1","sd-222333":"2","sd-333444":"2","sd-333555":"1"},
        {"id":"444","name":"Dwayne","most":"5","sd-111444":"1","sd-222444":"1","sd-333444":"1","sd-444555":"2"},
        {"id":"555","name":"Ed",    "most":"5","sd-111555":"1","sd-222555":"1","sd-333555":"2","sd-444555":"1"}
    ];

        workers.sort(function(a,b) {
            return (a.most == b.most)
                    ? (b["sd-" + a.id + b.id] - a["sd-" + a.id + b.id])
                    : (b.most - a.most);               
        });
    workers.forEach(function(elm){
        console.log(elm["id"] + " " +elm["name"]);
    });

在FF /铬/ Android版/ Android版Chrome浏览此输出。

In FF/Chrome/Android/Chrome for Android this outputs.

    222 Bruno
    111 April
    333 Carlos
    444 Dwayne
    555 Ed

在Safari和IE11(不得不改变,以提醒来查看数据),iOS和铬只有我获得尽可能不获取应用次要排序

In Safari and IE11 (had to change to alert to see the data) and chrome for IOS only I get as the secondary sort isn't getting applied

    111 April
    222 Bruno
    333 Carlos
    444 Dwayne
    555 Ed

请参阅小提琴

这是为什么?
有什么不这些浏览器支持?
我读到的forEach的文件没有提及在这些浏览器的支持问题,但我presume它不是用foreach作为排序的前手怎么回事?

Why is this? What don't these browsers support? I read the documentation about forEach which doesn't mention any support issues in these browsers, but I presume it isn't an issue with foreach as the sort is happening before hand?

<一个href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach\" rel=\"nofollow\">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

推荐答案

您都是靠参数的顺序 A B 来>提供给当您试图在人员查找信息

You are relying on the order of arguments a and b to the callback supplied to sort when you attempt to lookup information in workers:

b["sd-" + a.id + b.id] - a["sd-" + a.id + b.id] 

这顺序并不predictable并没有出现是跨浏览器一致的。在Firefox,我得到了下面看看起坐:

This ordering is not predictable and does not appear to be consistent across browsers. On Firefox, I get the following look-ups:

sd-111222 
sd-444555

在Safari浏览器,我得到这些(这是相反的顺序不存在):

On Safari, I get these (which are the reverse order do not exist):

sd-222111
sd-555444

您不应该依赖于这种排序。所有你知道的是,你在比较的部分的距离称为数组元素 A 一些的其他的数组中的元素称为 b 。你不能确定的其他东西。

You shouldn't rely on this ordering. All you know is that you are comparing some element from the array called a to some other element in the array called b. You can't be sure of anything else.

这篇关于JS在IE和Safari没有工作多列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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