ajax从后台获取全部的数据之后,现在分次显示在页面上。

使用ajax从后台获取到全部数据,要在页面分次显示, 之前是不断的调用ajax来分次显示,现在是在页面上做分次显示。


                  $.ajax({

                    type: "POST",

                    url: "./ajaxAutoComplete.do",

                    dataType:"json",

                    data: "method=getCityList&countryCode="+countryCode+"&offset="+offsetDate+"&isPage=false",

                    success: function(g_cityList){

                        var sCityTable = [];

                        var cityCodeArr = cityCodes.split(",");

                            $("#cityBtn").select({

                                dataType    : "cityName",

                                dataArray   : g_cityList,

                                dataCode    : cityCodeArr,

                                checkboxText:$("#cityCode"),

                            });

                        

                    }

                });    

                

success返回的是一个g_cityList数组,这个数据有几千条,怎么每次显示,比如一次显示1000条

这个数据生成的页面是用js写的,后台返回的数据直接导入到js中生成页面。

后端分页我已经完成,但是上司要求在前端分别。。


MMMHUHU
浏览 908回答 2
2回答

慕仙森

为什么不做成分页的形式?一次性获取全部的数据,然后前端在进行数据类似分页的处理,这种做法其实是比较不好的。

守候你守候我

这就是前端分页的问题,获取到数据后,然后渲染数据与页码第1页展示: 0-999的数据第2页展示: 1000-1999的数据第3页展示: 2000-2999的数据...就是说第page页,展示data中的数据开始位置start是 (page-1)*1000, limit是1000 ,用户点击某个页码按钮时,则直接从data获取数据并渲染。function render(page){&nbsp; &nbsp; let limit=1000,&nbsp; &nbsp; &nbsp; &nbsp; start=(page-1)*limit,&nbsp; &nbsp; &nbsp; &nbsp; html='';&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; for(let i=start, i<start+limit; i++){&nbsp; &nbsp; &nbsp; &nbsp; html += datap[i];&nbsp; &nbsp; }&nbsp; &nbsp; $('.tt').html(html);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript