0

我有这个 lngArr:

[
    {
        "data": {
            "18746": 20.75,
            "id": "18746",
            "impression": 20.75
        },
        "name": "Missing"
    },
    {
        "data": {
            "18748": 77.91,
            "id": "18748",
            "impression": 77.91
        },
        "name": "English"
    },
    {
        "data": {
            "18749": 0.02,
            "id": "18749",
            "impression": 0.02
        },
        "name": "Spanish"
    },
    {
        "data": {
            "18751": 0.31,
            "id": "18751",
            "impression": 0.31
        },
        "name": "Arabic"
    },
    {
        "data": {
            "18753": 0.01,
            "id": "18753",
            "impression": 0.01
        },
        "name": "Chinese"
    },
    {
        "data": {
            "18757": 0.01,
            "id": "18757",
            "impression": 0.01
        },
        "name": "Dutch"
    },
    {
        "data": {
            "18760": 0.01,
            "id": "18760",
            "impression": 0.01
        },
        "name": "French"
    },
    {
        "data": {
            "18763": 0.69,
            "id": "18763",
            "impression": 0.69
        },
        "name": "Hebrew"
    },
    {
        "data": {
            "18764": 0.08,
            "id": "18764",
            "impression": 0.08
        },
        "name": "Hindi"
    },
    {
        "data": {
            "18771": 0.2,
            "id": "18771",
            "impression": 0.2
        },
        "name": "Korean"
    },
    {
        "data": {
            "18772": 0.01,
            "id": "18772",
            "impression": 0.01
        },
        "name": "Latvian"
    },
    {
        "data": {
            "18786": 0.01,
            "id": "18786",
            "impression": 0.01
        },
        "name": "Turkish"
    }
]

这是我的排序代码:

lngArr.sortBy(function(lng) {
                return -lng.data.impression;
            });

我不知道为什么它不起作用。这是文档

4

1 回答 1

1

说明返回时,文档可能有点不清楚Array,但来源清除了这一点:

返回一个的(排序的)数组。

所以你可能想做

lngArr = lngArr.sortBy(function(lng) {
    return -lng.data.impression;
});
于 2014-09-12T12:10:53.180 回答