thymeleaf动态列id展⽰总结;thymeleaf列ID⾃增,动态设置
ID,表格操作总结;
持续更新贴·················
分享⼀个项⽬⽤到的例⼦:
⼀共⽤到了if、unless、text、id、onclick等属性,相当于是个⼊门级别的
关于表格⾃增ID,耽搁了很长时间,在这⾥⽤了thymeleaf的th:id标签,
要使⽤id属性,在each中⼀定要声明两个参数,
在后⾯引⽤的时候text属性展⽰内容,id后⾯设置⾃增(注意语法),
其实这个⾥⾯我没有取到index,也就是indexInc.index是0,但是既然⾃增,初始值是多少暂时忽略了;
我在这⾥设置触发事件的时候⽤了th:onclick,语法很奇怪,参数传了⾃增之后的index,因为id是拼起来的,在后台获取的时候,也拼⼀下
ID就可以取到对应属性值;
但是不知道⽤thymeleaf 怎么给值为空的表格设置默认值,就是那种字体灰⾊的提⽰语,点击编辑之后提⽰语⾃动消失,
thyme再探索⼀下;
实际代码:
<tr th:if="${#lists.isEmpty(goodsList)}" ><td colspan="15">没有数据</td></tr>
<tr th:unless="${#lists.isEmpty(goodsList)}" id="proNmSelectList" th:each="map,indexInc:${goodsList}"> 
<!--<td><input type="checkbox" name="proNmSelect" th:value="${map.proId}" /></td>-->
<td th:text="${map.showOrder}" th:id = "showOrder+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${map.proId}" th:id = "proId+(${indexInc.index}+1)"></td>
<td th:text="${map.proNm}" th:id = "proNm+(${indexInc.index}+1)"></td>
<td th:text="${map.proExplain}" th:id = "proExplain+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${map.picLocation}" th:id = "picLocation+(${indexInc.index}+1)" contenteditable="true"></td>
<td th:text="${#dates.format(map.startDate,'yyyy-MM-dd HH:mm:ss')}" th:id = "startDate+(${indexInc.index}+1)" onclick="dateFormate()" contenteditable="true"    <td th:text="${#dates.dDate,'yyyy-MM-dd HH:mm:ss')}" th:id = "endDate+(${indexInc.index}+1)" onclick="dateFormate()" contenteditable="true">    <td th:text="${map.actId}" th:id = "actIdIn+(${indexInc.index}+1)"></td>
<td>
<a th:onclick="|addRecommendGoods((${indexInc.index}+1))|" >提交</a>  
<a th:onclick="|deleteRecommendGoods((${indexInc.index}+1))|" >删除</a>
</td>
</tr>
下⾯这个收集的资料⾃⼰留⽤,未经验证:
⼀、引⽤命名空间 <html xmlns:th="">
7.2 switch 语句

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。