通过OBJECTID通过Javascript ASC或DESC对JSON对象进行排序

时间:2016-01-18 03:05:34

标签: javascript json twitter

我正尝试通过" id"从以下网址http://acweb.ddns.net/usertweets.php对以下JSON twitter Feed对象进行排序这是"状态"下的子节点。

function sortJsonArrayByProperty(objArray, prop, direction){
if (arguments.length<2) throw new Error("sortJsonArrayByProp requires 2 arguments");
var direct = arguments.length>2 ? arguments[2] : 1; //Default to ascending

if (objArray && objArray.constructor===Array){
    var propPath = (prop.constructor===Array) ? prop : prop.split(".");
    objArray.sort(function(a,b){
        for (var p in propPath){
            if (a[propPath[p]] && b[propPath[p]]){
                a = a[propPath[p]];
                b = b[propPath[p]];
            }
        }
        // convert numeric strings to integers
        a = a.match(/^\d+$/) ? +a : a;
        b = b.match(/^\d+$/) ? +b : b;
        return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) );
    });
}

}

我尝试通过

使用上面的以下功能
var feedsSort = fsortJsonArrayByProperty(feed, 'statuses.id', -1);
然而,它尝试失败了。

0 个答案:

没有答案