Boostrap table 最后一页删除后,数据异常

Boostrap table 最后一页删除后,数据异常

主要问题:BootStrap Table后台分页时前台删除最后一页所有数据refresh刷新后无数据的问题。

产生原因:主要是页码超出范围带来的问题。

解决方法:通过修改bootstrap-table.js的initServer方法中的查询success回调函数解决,将该回调函数改为:

success:function (res) { 

     /**TODO:2018-8-3新加的代码,处理页码错误问题开始*/
    //当总记录数不为0而当前页的记录数为0时将页码设为最后一页重新请求数据,即:
    if(that.options.pagination&&res.total&&!res.rows.length){//总记录数大于0,但当前页记录数为0,则此时页码超过了最大页码
        that.options.pageNumber = Math.ceil(res.total/that.options.pageSize);//最后一页(总页数)
        that.initServer();
        return;
    }
    /**2018-8-3新加的代码,处理页码错误问题结束*/

    res = calculateObjectValue(that.options, that.options.responseHandler, [res], res); 
    that.load(res); 
    that.trigger('load-success', res); 
   }

小贴士:可以通过搜索“success: function”来快速定位代码位置。

猜你喜欢

转载自blog.csdn.net/LitongZero/article/details/81381475