持续更新贴·················
分享一个项目用到的例子:
一共用到了if、unless、text、id、onclick等属性,相当于是个入门级别的
关于表格自增ID,耽搁了很长时间,在这里用了thymeleaf的th:id标签,
要使用id属性,在each中一定要声明两个参数,
在后面引用的时候text属性展示内容,id后面设置自增(注意语法),
其实这个里面我没有取到index,也就是indexInc.index是0,但是既然自增,初始值是多少暂时忽略了;
我在这里设置触发事件的时候用了th:onclick,语法很奇怪,参数传了自增之后的index,因为id是拼起来的,在后台获取的时候,也拼一下ID就可以取到对应属性值;
但是不知道用thymeleaf 怎么给值为空的表格设置默认值,就是那种字体灰色的提示语,点击编辑之后提示语自动消失,
再探索一下;
实际代码:
<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)" onc