1.前台
1.1.使用二维map来存储分页信息:
1.1.1.一维map存储页码和分页信息,key为页码,value为分页信息。
1.1.2.二维map存储分页的上一页,当前页,下一页信息。
1.1.3.当为第一页时,map[1]["prePage"]="",map[1]["currPage"]="",map[1]["nextPage"]=取到第一页数据后的continuation信息;当为第二页时,map[2]["prePage"]=map[1]["currPage"],map[2]["currPage"]=map[1]["nextPage"],map[2]["nextPage"]=取到第二页数据后的continuation信息。
2.后台
2.1.如果第一次获取:
{Tab,Continue} = ets:match(users,'$1',10),
Tab:取到的当前页的所有数据信息。
Continue:当前页的下一页信息。
将所有的数据信息和下一页信息发送到前台
2.2.如果下一次获取并且下一页的数据是从前台传过来的
%将前台传过来的分页数据进行解析 [Tab1,Int1,Int2,Bin,List,Int3] = string:tokens(Continuation,"_"), %将前台传过来的分页数据按照Continue规则进行组装 Continue1 = {list_to_atom(Tab1),list_to_integer(Int1),list_to_integer(Int2),<<>>,[],0}, %将自定义的分页数据根据此规则进行修复 MS = ets:fun2ms(fun( OrderRecord = #users{}) -> [OrderRecord] end), Continue2 = ets:repair_continuation(Continue1, MS), %将下一页的数据信息取出 {Tab2,Continue3} = ets:match(Continue2), 将所有的数据信息和下一页信息发送到前台
2.3.获取的下一页的数据信息:
2.3.1.如果是最后一页:
Continue='$end_of_table'.
2.3.2.如果不是最后一页:
Continue={Tab,Int1,Int2,Bin,List,Int3}
本文详细介绍了前端通过二维map存储分页信息的方法,并结合后台Erlang的ETS表匹配技术实现前后端交互的分页数据获取流程。针对首次获取和后续页面加载情况,文章给出了具体的实现步骤和示例。
2841

被折叠的 条评论
为什么被折叠?



