使用Rest API进行分页

时间:2015-05-05 08:21:53

标签: javascript jquery

我想使用restful api进行分页,这是我用于显示数据的js代码。我只需要显示来自json api的6个数据。

   success: function(data){
    var arr = data.data;
    var htmlText = '';
        for ( var key in arr ) {
            htmlText += '<div class="feed-element">';
            htmlText += '<a href="profile.html" class="pull-left">';
            htmlText += '<img alt="image" class="img-circle" src= '+ arr[key].image +' >';
            htmlText += '</a>';
            htmlText += '<div class="media-body ">';
            htmlText += '';
            htmlText += '<p class="user-name"> Name: ' + arr[key].name + '</p>';
            htmlText += '<p class="user-loc"> Location: ' + arr[key].location + '</p>';
            htmlText += '<p class="user-desc"> Description: ' + arr[key].description + '</p>';
            htmlText += '<p class="user-created"> Created at: ' + arr[key].created_at + '</p>';
            htmlText += '</div>';
            htmlText += '</div>';
        }

        $('.feed-activity-list').append(htmlText);
    }

这是我的json数据,这里是分页的total_count。

"status": 200,
"data": [
    {
        "name": "virendra rajpurohit ",
        "location": "Kanodiya purohitan ",
        "description": "I m show happy.. rajpurohitaap downloads..",
        "image": "https://rajpurohit.s3-us-west-2.amazonaws.com/images/18770_20150505071218.jpg",
        "created_by": 52952,
        "users_name": "Virendra rajpurohit",
        "comment_count": 0
    },
    {
        "name": "Prakash Rajpurohit",
        "location": "Asotra",
        "description": "Jay datari saa",
        "image": "https://rajpurohit.s3-us-west-2.amazonaws.com/images/26457_20150505070131.jpg",
        "created_by": 55752,
        "users_name": "Amarsingh Rajpurohit",
        "comment_count": 0
    },
],
"total_count": 201
}

现在,请告诉我如何处理分页。我不知道要处理这件事。请帮我。提前谢谢。

0 个答案:

没有答案