Thymeleaf+layui+jquery复选框回显
一、Thymeleaf+layui+jquery复选框回显
基于Thymeleaf模板下的layui+jquery复选框回显,主要是jquery。大致意思是:把数组转成JSON传到前台,再在前台转回数组 AJAX一般都是用JSON格式或XML格式来传递数据的JSON就是一种具有特殊格式的字符串。
1.实体类属性
1 //顾客等级
2 private Integer[] constomerGradeArray;
3 //用来存储json格式的顾客等级数组(方便数据传输)
4 private String constomerGradeString;
2.后台返回
@RequestMapping("goodsTypeList")
public String goodsType_list(Client client,Model model){
if(client!=null){
//将数组转为json格式
client.setConstomerGradeString(JSON.toJSONString(client.getConstomerGradeArray()));
model.addAttribute("client",client);
}
return "goodsType_list";
}
3.前台页面<div class="layui-form-item">
<label class="layui-form-label">客户等级</label>
<div class="layui-input-inline" id="constomerGradeArray">
<!-- 如果是layui的表单提交input标签的name值是constomerGradeArray[] -->
<!-- 不然就会导致只提交过去一个值 (本人使用var data=$("form").serialize();) -->
<input type="checkbox" name="constomerGradeArray" value="1" title="高级客户">
<input type="checkbox" name="constomerGradeArray" value="2" title="VIP客户">
</div>
</div>
4.jquery
layui.use(['form','jquery'], function(){
var form = layui.form;
var $ = layui.jquery; $(function () { if('[[${client.constomerGradeString}]]'!='null'){
//获取后台json /*用jQuery处理传过来的json值*/
var constomerGradeString=$.parseJSON('[[${client.constomerGradeString}]]');
//获取所有复选框的值
var constomerGradeArray = $("input[name='constomerGradeArray']");
//遍历json数组
$.each(constomerGradeString,function(i,json){
//获取所有复选框对象的value属性,用json数组和他们匹配,如果有,则说明他应被选中
$.each(constomerGradeArray,function(j,checkbox){
//获取复选框的value属性
var checkValue=$(checkbox).val();
if(json==checkValue){
$(checkbox).attr("checked",true);
}
})
//重新渲染(很重要:因为页面是用layui画的)
form.render();
})
}
})
})
}
参考链接:
json转换:https://www.cnblogs.com/YeHuan/p/11221504.html 或 https://blog.csdn.net/qq_37444478/article/details/76209189
主要代码:https://blog.csdn.net/w18853851252/article/details/82888109
表单渲染:https://blog.csdn.net/qq_33048333/article/details/80609553
Thymeleaf+layui+jquery复选框回显的更多相关文章
- 复选框回显、全选、非全选、cookie处理数据、json数组对象转换处理学习笔记参考的页面
<%@include file="/common/head.jsp"%> <%@ page contentType="text/html; charse ...
- Element-ui框架checkbox复选框回显
先看下效果是不是你需要的..... 然后废话不多说,上代码,希望能够帮助到你... <template> <div class=''> <el-form label-wi ...
- js 复选框回显
<div class="control-group"> <label class="control-label">客户状态:</l ...
- jquery复选框 选中事件 及其判断是否被选中
jquery复选框 选中事件 及其判断是否被选中 (2014-07-25 14:03:54) 转载▼ 标签: jquery复选框选中事件 分类: extjs jquery 今天做了 显示和不显示密 ...
- Jquery复选框
Jquery复选框 1.checkbox list选择 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- layui 添加复选框checkbox后,无法正确显示及点击的方法
layui 添加复选框checkbox后,无法正确显示方式,这个是由于html里的样式添加 layui-form后,没有加载 form插件 ,具体如下: <body style="ba ...
- jquery 复选框
jquery 选中复选框 $("input[type='checkbox']").prop("checked", true); jquery 判断复选框是否被选 ...
- jQuery 复选框全选/取消全选/反选
jQuery实现的复选框全选/取消全选/反选及获得选择的值. 完整代码: <!DOCTYPE html> <html> <head> <script type ...
- Jquery复选框的全选全不选及选择所有复选框实现全选的复选框
Jquery代码 $(function () { $(":checkbox.parentfunc").click(function () { //如何获取被点击的那个复选框 $(t ...
随机推荐
- C++ substr 的两个用法
substr是C++语言函数,主要功能是复制子字符串,要求从指定位置开始,并具有指定的长度. basic_string substr(size_type _Off = 0,size_type _C ...
- 9组-Alpha冲刺-1/6
一.基本情况 队名:不行就摆了吧 组长博客:https://www.cnblogs.com/Microsoft-hc/p/15526668.html 小组人数: 8 二.冲刺概况汇报 谢小龙 过去两天 ...
- 25.A Famous Music Composer
描述 Mr. B is a famous music composer. One of his most famous work was his set of preludes. These 24 p ...
- Git项目迁移(把当前git项目迁移到新的git地址)
使用 git clone --bare 命令clone当前git git clone --bare http://gitlab.xxx/demo.git 推到新的git地址 cd demo.git g ...
- Visual Studio中使用Macros插件给代码添加注释、时间和以及自动脚本
title: Visual Studio中使用Macros插件给代码添加注释.时间和以及自动脚本 date: 2020-09-11 sidebarDepth: 2 tags: 代码 Visual st ...
- Salesforce Consumer Goods Cloud 浅谈篇三之 行动计划(Action Plan)相关配置
本篇参考: https://v.qq.com/x/page/f0772toebhd.html https://v.qq.com/x/page/e0772tsmtek.html https://v.qq ...
- Nginx的try_files指令使用实例
Nginx的配置语法灵活,可控制度非常高.在0.7以后的版本中加入了一个try_files指令,配合命名location,可以部分替代原本常用的rewrite配置方式,提高解析效率. try_file ...
- [loj3347]有趣的旅途
考虑求出重心,以0为根建树,求出第 $i$个点的子树大小$sz[i]$($a(0,i)$),则满足$n-sz[i]\le \lfloor\frac{n}{2}\rfloor$的$sz[i]$中的最小值 ...
- maven插件慢的解决方案
-DarchetypeCatalog=local 地址:https://www.cnblogs.com/del88/p/6286887.html
- 【豆科基因组】大豆适应性位点GWAS分析 [转载]
目录 材料与方法 结果分析 本文利用99085个高质量SNP 通过STRUCTURE,PCA和neighbour-joining tree的群体结构分析将地方品种分为三个亚群,这些亚群表现出地理上的遗 ...