demo2.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <title>功能演示2 - 通用分页组件</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>分页演示二</cite></a>
  7. </div>
  8. </div>
  9. <div class="layui-fluid">
  10. <div class="layui-row layui-col-space15">
  11. <div class="layui-col-md12">
  12. <div class="layui-card">
  13. <div class="layui-card-header">显示完整功能</div>
  14. <div class="layui-card-body">
  15. <div id="test-laypage-demo7"></div>
  16. </div>
  17. </div>
  18. </div>
  19. <div class="layui-col-md12">
  20. <div class="layui-card">
  21. <div class="layui-card-header">自定义排版</div>
  22. <div class="layui-card-body">
  23. <div id="test-laypage-demo8"></div>
  24. <div id="test-laypage-demo9"></div>
  25. <div id="test-laypage-demo10"></div>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="layui-col-md12">
  30. <div class="layui-card">
  31. <div class="layui-card-header">自定义每页条数的选择项</div>
  32. <div class="layui-card-body">
  33. <div id="test-laypage-demo11"></div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="layui-col-md12">
  38. <div class="layui-card">
  39. <div class="layui-card-header">将一段已知数组分页展示</div>
  40. <div class="layui-card-body">
  41. <div id="test-laypage-demo20"></div>
  42. <ul id="test-laypage-biuuu_city_list"></ul>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <script>
  49. layui.use(['admin', 'laypage'], function(){
  50. var laypage = layui.laypage;
  51. //完整功能
  52. laypage.render({
  53. elem: 'test-laypage-demo7'
  54. ,count: 100
  55. ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
  56. ,jump: function(obj){
  57. console.log(obj)
  58. }
  59. });
  60. //自定义排版
  61. laypage.render({
  62. elem: 'test-laypage-demo8'
  63. ,count: 1000
  64. ,layout: ['limit', 'prev', 'page', 'next']
  65. });
  66. laypage.render({
  67. elem: 'test-laypage-demo9'
  68. ,count: 1000
  69. ,layout: ['prev', 'next', 'page']
  70. });
  71. laypage.render({
  72. elem: 'test-laypage-demo10'
  73. ,count: 1000
  74. ,layout: ['page', 'count']
  75. });
  76. //自定义每页条数的选择项
  77. laypage.render({
  78. elem: 'test-laypage-demo11'
  79. ,count: 1000
  80. ,limit: 100
  81. ,limits: [100, 300, 500]
  82. });
  83. //将一段数组分页展示
  84. //测试数据
  85. var testLayPageData = [
  86. '北京',
  87. '上海',
  88. '广州',
  89. '深圳',
  90. '杭州',
  91. '长沙',
  92. '合肥',
  93. '宁夏',
  94. '成都',
  95. '西安',
  96. '南昌',
  97. '上饶',
  98. '沈阳',
  99. '济南',
  100. '厦门',
  101. '福州',
  102. '九江',
  103. '宜春',
  104. '赣州',
  105. '宁波',
  106. '绍兴',
  107. '无锡',
  108. '苏州',
  109. '徐州',
  110. '东莞',
  111. '佛山',
  112. '中山',
  113. '成都',
  114. '武汉',
  115. '青岛',
  116. '天津',
  117. '重庆',
  118. '南京',
  119. '九江',
  120. '香港',
  121. '澳门',
  122. '台北'
  123. ];
  124. //调用分页
  125. laypage.render({
  126. elem: 'test-laypage-demo20'
  127. ,count: testLayPageData.length
  128. ,jump: function(obj){
  129. //模拟渲染
  130. document.getElementById('test-laypage-biuuu_city_list').innerHTML = function(){
  131. var arr = []
  132. ,thisData = testLayPageData.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
  133. layui.each(thisData, function(index, item){
  134. arr.push('<li>'+ item +'</li>');
  135. });
  136. return arr.join('');
  137. }();
  138. }
  139. });
  140. });
  141. </script>