Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打开图形API排序顺序,或简单的jQuery/JavaScript排序_Javascript_Jquery_Facebook Graph Api_Sorting - Fatal编程技术网

打开图形API排序顺序,或简单的jQuery/JavaScript排序

打开图形API排序顺序,或简单的jQuery/JavaScript排序,javascript,jquery,facebook-graph-api,sorting,Javascript,Jquery,Facebook Graph Api,Sorting,通过拨打以下电话,我将获得一份好友分数列表: https://graph.facebook.com/<appid>/scores?access_token=' + userToken; https://graph.facebook.com//scores?access_token='+userToken; 它工作得很好,但我想按最高分数(result.score)排序。有很多分页选项,比如“limit,offset,until”,您可以在URL中内联指定,但是我在文档中没有看到任

通过拨打以下电话,我将获得一份好友分数列表:

https://graph.facebook.com/<appid>/scores?access_token=' + userToken;
https://graph.facebook.com//scores?access_token='+userToken;
它工作得很好,但我想按最高分数(result.score)排序。有很多分页选项,比如“limit,offset,until”,您可以在URL中内联指定,但是我在文档中没有看到任何排序选项

如果不可能,那么jQuery或JavaScript中对以下语句排序的最简单方法是什么

 success: function (data) {
     $("#highScores").html("");
     $.each(data.data, function (i, item) {
         $("#highScores").append("<div class='score'><span class='scoreName'>" + item.user.name + "</span><span class='scoreValue'>" + item.score + "</span>");
     });
 },
成功:函数(数据){
$(“#高分”).html(“”);
$.each(data.data,function(i,item){
$(“#高分”).append(“+item.user.name+”+item.score+”);
});
},

我刚刚想到了一个技巧,如果没有更简单的解决方案,我会使用它

保存最后一个分数,如果新分数更高,则执行prepend而不是append

    success: function (data) {
        $("#highScores").html("");
        var lastScore = 0;
        $.each(data.data, function (i, item) {
            if (lastScore < item.score) {
                $("#highScores").prepend("<div class='score'><span class='scoreName'>" + item.user.name + "</span><span class='scoreValue'>" + item.score + "</span>");
            } else {
                $("#highScores").append("<div class='score'><span class='scoreName'>" + item.user.name + "</span><span class='scoreValue'>" + item.score + "</span>");
            }
            lastScore = item.score;
        });
    },
成功:函数(数据){
$(“#高分”).html(“”);
var lastScore=0;
$.each(data.data,function(i,item){
如果(最后得分<项目得分){
$(“#高分”).prepend(“+item.user.name+”+item.score+”);
}否则{
$(“#高分”).append(“+item.user.name+”+item.score+”);
}
lastScore=item.score;
});
},