前言:年初公司准备自己做一个视频学习网站,第一次用layui作为前端框架
1.关于table的数据渲染:需要后台传递的json包含以下内容,由于公司后台框架的自动封装导致这个格式一直弄不出来
{
"code": 0,
"msg": "",
"count": 1000,
"data": [{}, {}]
} 后台的处理
Dataset ds = new Dataset(dbSlrad);
ds.setEnablePaging(false);
int limit = Integer.parseInt(params.get("limit").toString());
int page = Integer.parseInt(params.get("page").toString());
String range = limit*(page-1) + "," + limit*page;
String sql = "select user_id,user_name,depart_name,user_role,"
+ "date_format(create_time, '%Y-%m-%d %H:%i:%s') AS create_time"
+ " from tbl_user limit "+range;
ArrayList<Object[]> ulist = ds.list(sql);
JSONArray json = new JSONArray();
JSONObject jsontemp;
int i=0;
for(Object[] temp : ulist) {
jsontemp = new JSONObject();
jsontemp.put("user_id", temp[0]);
jsontemp.put("user_name", temp[1]);
jsontemp.put("depart_name", temp[2]);
jsontemp.put("user_role", temp[3]);
jsontemp.put("create_time", temp[4]);
json.put(i,jsontemp);
i++;
}
JSONObject jsresult= new JSONObject();
jsresult.put("code", 0);
jsresult.put("msg","");
jsresult.put("count",数据总量);
jsresult.put("data", json);
//System.out.println(jsresult.toString());
HttpServletResponse response = WebContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter out;
try {
out = response.getWriter();
//这里如果JSONObject不转成String 会报异常
WebContext.getRequest().setAttribute("sl.respjson", jsresult.toString());
out.print(jsresult);
out.flush();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}2.关于layer获取父页面table中的数据
可在父页面定义一个全局变量var XXX = "",然后再layer中 通过parent.XXX 即可获取,这样可获取一个对象 而"xxxx.html?sss="?+sss这样的方式只能传递一个参数
3.关于layui第三方组件 layui.extends关联选择框以及多选框
在做修改功能的时候,要实现上述两个默认选中,selectM组件 selected的传值 不能识别
var tagIns2 = selectM({
//元素容器【必填】
elem: '#tag_ids2'
//候选数据【必填】
,
data: window._h5_config.server_url + 'ClassService.classPublic.slrad'
//默认值
,
//最多选中个数,默认5
,
max: 6
//input的name 不设置与选择器相同(去#.)
,
name: 'class_public'
//值的分隔符
,
delimiter: ','
//候选项数据的键名
,
verify: 'required',
field: {
idName: 'id',
titleName: 'name'
}
});
//arr为数组 直接把arr塞入selected: []是不起作用的
tagIns2.set(arr);
版权声明:本文为Dawn1124原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。