th:each属性用于迭代循环,语法:th:each="obj,iterStat:${objList}"
迭代对象可以是Java.util.List,java.util.Map,数组等;
iterStat称作状态变量,属性有:
index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个
<th:block th:if="${goods.goodSpecResponses!=null}">
<div class="row" th:each="obj,iterStat : ${goods.goodSpecResponses}"
id="spec_row_1">
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-3 control-label"><span
style="color: red; ">*</span>规格:</label>
<div class="col-sm-9">
<input th:id="${'spec_name_'+iterStat.count}"
placeholder="请输入规格"
class="form-control"
type="text" maxlength="30">
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-3 control-label"><span
style="color: red; ">*</span>价格:</label>
<div class="col-sm-9">
<input th:id="${'spec_price_'+iterStat.count}"
placeholder="请输入价格"
οnkeyup="value=value.replace(/[^d.]/g,'')"
class="form-control" type="text" maxlength="30"
>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-3 control-label"><span
style="color: red; ">*</span>库存:</label>
<div class="col-sm-9">
<input th:id="${'spec_stock_'+iterStat.count}"
οnkeyup="value=value.replace(/[^d.]/g,'')"
placeholder="请输入库存" class="form-control"
type="text"
maxlength="30"
>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<input type="button" th:onclick="'delspecrow('+count+')'"
class="btn btn-sm btn-danger" value="删除">
</div>
</div>
</div>
</th:block>