jquery排序json对象

Ami*_*mit 3 sorting jquery json

我在jquery中有以下Json对象,我用它来填充jquery网格.

现在我需要在"performanceName"的基础上对它进行排序.

请告诉我如何实现这一目标.请我知道相同的问题是100次发布但仍然努力在json下面实施排序

{
    "callback": "",
    "html": "",
    "message": [
        ""
    ],
    "responseData": [
        {
            "collectionTitleId": 1107861,
            "collectionTitleIdSpecified": true,
            "performanceField": {
                "addedDate": "6/16/2011 11:11:10 PM",
                "artist": "Corbis",
                "performanceName": "Showcase Graphic 003 - Anime Girl Purple",
                "performanceType": "Graphic",
                "provider": "DMSP Dynamic Digital"
            },
            "sortOrder": "01"
        },
        {
            "collectionTitleId": 1113513,
            "collectionTitleIdSpecified": true,
            "performanceField": {
                "addedDate": "5/25/2011 9:27:39 AM",
                "artist": "Beloved",
                "performanceName": "Hating On Your Feet (Verse)",
                "performanceType": "LabelTone",
                "provider": "p1"
            },
            "sortOrder": "02"
        }
    ],
    "status": [
        "Success"
    ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

And*_*y E 10

您可以使用Array.prototype.sort就地排序数组.没有任何参数,这会尝试按字母顺序对元素进行排序,但您可以传入比较函数.此函数接收两个参数,并且应返回小于0,0或大于0的值,以定义参数1与参数2相关的位置.

您的排序功能应如下所示:

data.responseData.sort(function (a, b) {
    a = a.performanceField.performanceName,
    b = b.performanceField.performanceName;

    return a.localeCompare(b);
});
Run Code Online (Sandbox Code Playgroud)

工作演示:http://jsfiddle.net/AndyE/aC5z4/

localeCompare 为我们比较字符串的艰苦工作.