Load the pull-down refresh module on APICloud

apicloud has a built-in upload and pull-down refresh, which can also be used by a third party or in the module library.

1. Pull down to refresh, the following code is written in

apiready = function (){} inside
apiready = function (){
         // pull down to refresh 
        api.setRefreshHeaderInfo({
            visible: true,
            bgColor: 'rgba(0,0,0,0)',
            textColor: '#666',
            textDown: ' Pull down to refresh ' ,
            textUp: ' Release refresh '
        }, function (ret, err) {
            toDoRequest();
        });
    };

    // Refresh initialization loading 
    function toDoRequest(){
        setTimeout(function(){
            api.refreshHeaderLoadDone(); // Reset pull-down refresh 
            api.toast({
                msg: ' already the latest data ' ,
                duration:'1000',
                localtion:'middle'
            });
        },2000)
    }

 

2. Realize loading more:

This is achieved by listening to the page scroll to the bottom event:

apiready = function(){
    api. addEventListener({name:'scrolltobottom'}, function(ret, err){
        //refresh event callback
        toDoRequest();
    });
}

//do ajax
function toDoRequest(){
    // GET、POST、PUT、DELETE、…
    api.ajax({
        url:'http://xxx.xxx.xxx'
    }, function (ret, err) {
        //do your business
    });
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216557&siteId=291194637