如何分批显示循环结果

时间:2019-05-21 00:18:07

标签: javascript jquery

我想以100为批次显示循环的结果。我想显示从前100开始,如果滚动直到到达表格底部,然后再加载100,然后继续那个。

//I know this is the code for knowing when the scroll of the window is at the bottom, but how can I modify it to get the scroll from the table..
$(window).scroll(function() {
    if($(window).scrollTop() == $(document).height() - $(window).height()) {
    }
});

这是我的循环

function redemptionRewards(locationID){
    var date1 = dateStart
    var date2 = dateEnd

    let success = function(res) {
    let redemptionsCoinsRewards1 = res['redemptionsCoinsRewards1']

        for(i=0; i<redemptionsCoinsRewards1.length;i++){

        let type1 = redemptionsCoinsRewards1[i]['type']
        if(type1 != null){
        let typeCapital1 = type1.charAt(0).toUpperCase() + type1.slice(1)

        let timeCR1 = redemptionsCoinsRewards1[i]['date']
        let locationCR1 = redemptionsCoinsRewards1[i]['location']
        let firstName1 = redemptionsCoinsRewards1[i]['name']
        let lastName1 = redemptionsCoinsRewards1[i]['lastname']



        $('#redeemptionsTable1 tbody').append(`             
              <tr class='redempTableRows'>
              <td class='redemption'>${typeCapital1} </td>
              <td class='redemption-location'>${locationCR1} </td>
              <td class='redemption-user'> ${firstName1} ${lastName1} </td>
        </tr>`)
        }
        }
    }
    $.ajax({
            type: 'POST',
        url: '/api/redemptionsCoinsRewards1',
        crossDomain: true,
        success: success,
        dataType: 'json',
        data: {
            locationID : locationID,
            date1 : date1,
            date2 : date2
        }
    });

}

我已经对此进行了一些研究,但找不到帮助的答案,因此我们将不胜感激!

0 个答案:

没有答案