thinkphp+layui系统开发笔记(一)——数据表格
2022-11-24 11:10:29
211
{{single.collect_count}}

一、参考资料:

1.thinkphp: https://www.kancloud.cn/special/thinkphp5_quickstart

2.layui: http://www.layui.com/doc/modules/table.html

二、代码:

主体html

<table id="demo" lay-filter="test"></table>

JS构建:(此处采用自动构建)

<script src="/layui/layui.js"></script><script>layui.use('table', function(){var table = layui.table;//第一个实例table.render({elem: '#demo',height: 315,url: '/demo/table/user/' //数据接口,page: true //开启分页,cols: [[ //表头{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'},{field: 'username', title: '用户名', width:80},{field: 'sex', title: '性别', width:80, sort: true},{field: 'city', title: '城市', width:80} ,{field: 'sign', title: '签名', width: 177},{field: 'experience', title: '积分', width: 80, sort: true},{field: 'score', title: '评分', width: 80, sort: true},{field: 'classify', title: '职业', width: 80},{field: 'wealth', title: '财富', width: 135, sort: true}]]});});</script>

■首先引入layui.js

height:支持数字或者“full-100”等;

url:从控制器端返回符合格式的JSON数据,数据格式见官网手册;之前在学习这里的时候浪费不少时间,其实很简单。就是TP5控制器调用模型方法获取数据,并构建一个符合条件的数组,再JSON()格式化;

$data = Model($model)->getDataM($condition,$searchVal);
$res = ['code'=>0,'msg'=>'','count'=>$total,'data'=>$data];        return json($res);

cols:表头可以自己写,推荐将表头信息写入数据表,并用上述方式返回。

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}