layui分页查询

提问 已结 11 323
Zzn南
Zzn南 2019-11-20
悬赏:20飞吻
//调用分页
laypage.render({
elem: 'demo20'
,count: data.length
,jump: function(obj){
//模拟渲染
document.getElementById('biuuu_city_list').innerHTML = function(){
var arr = []
,thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
layui.each(thisData, function(index, item){
arr.push('<li>'+ item +'</li>');
});
return arr.join('');
}();
}
});

});
除了item参数外 还想要在传入一个日期值,“ var arr = [],thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);” 这个地方该怎么改呢?
回帖
  • IDyun
    2019-11-20
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="//res.layui.com/layui/dist/css/layui.css" media="all">
    <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
    </head>
    <body>


    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>将一段已知数组分页展示</legend>
    </fieldset>

    <div id="demo20"></div>
    <ul id="biuuu_city_list"></ul>


    <script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
    <!-- 注意:如果你直接复制所有代码到本地,上述js路径需要改成你本地的 -->
    <script>
    layui.use(['laypage', 'layer'], function(){
    var laypage = layui.laypage
    ,layer = layui.layer;

    //将一段数组分页展示

    //测试数据
    var data = [
    {"bt":"xxx1新闻","date":"2019-11-20"},
    {"bt":"xxx2新闻","date":"2019-11-20"},
    {"bt":"xxx3新闻","date":"2019-11-20"},
    {"bt":"xxx4新闻","date":"2019-11-20"},
    {"bt":"xxx5新闻","date":"2019-11-20"},
    {"bt":"xxx6新闻","date":"2019-11-20"},
    {"bt":"xxx7新闻","date":"2019-11-20"},
    {"bt":"xxx8新闻","date":"2019-11-20"},
    {"bt":"xxx9新闻","date":"2019-11-20"},
    {"bt":"xxx10新闻","date":"2019-11-20"},
    {"bt":"xxx11新闻","date":"2019-11-20"},
    {"bt":"xxx12新闻","date":"2019-11-20"},
    {"bt":"xxx13新闻","date":"2019-11-20"},
    {"bt":"xxx14新闻","date":"2019-11-20"},
    {"bt":"xxx15新闻","date":"2019-11-20"},
    {"bt":"xxx16新闻","date":"2019-11-20"},
    {"bt":"xxx17新闻","date":"2019-11-20"},
    {"bt":"xxx18新闻","date":"2019-11-20"}
    ];

    //调用分页
    laypage.render({
    elem: 'demo20'
    ,count: data.length
    ,jump: function(obj){
    //模拟渲染
    document.getElementById('biuuu_city_list').innerHTML = function(){
    var arr = []
    ,thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
    layui.each(thisData, function(index, item){
    arr.push('<li>'+ item.bt +' '+ item.date+'</li>');
    });
    return arr.join('');
    }();
    }
    });

    });
    </script>

    </body>
    </html>
    0 回复
  • Zzn南
    2019-11-20
    增加一个和item的同级参数date
    0 回复
  • Zzn南
    2019-11-20
    类似这种
    0 回复
  • IDyun
    2019-11-20
    你要分页的数据格式是怎样的?
    0 回复
  • Zzn南
    2019-11-20
    @IDyun 你好,我的分页数据格式是“bt”:"xxx新闻",“date”:"2019-11-20"这种
    0 回复
  • IDyun
    2019-11-20
    如果 数据格式像下面这样,直接点出来就可以了。

     var data = [{"id":10010,"username":"user-10"},{"id":10011,"username":"user-11"}]
    arr.push('<li> id ='+ item.id +' username= '+ item.username+'</li>');
    0 回复
  • Zzn南
    2019-11-20
    @IDyun 左边是标题 最右边是创建时间
    0 回复
  • Zzn南
    2019-11-20
    @IDyun 取出来的值,我放到了两个数组里面
    0 回复
  • IDyun
    2019-11-20
    不需要分开,用原先的数组就可以了。
    0 回复
  • Zzn南
    2019-11-20
    @IDyun 好的,这个“.splice(obj.curr*obj.limit - obj.limit, obj.limit);” 这一块怎么改呢?data我换为了我那个数组,这块报错
    0 回复