如何使用thymeleaf在javascript中使用for循环?
我正在使用thymeleaf,所以当我运行这个应用程序时,它会在(for)(int I=0;I)中给我一个错误*/ 当前的脚本模式是javascript (th:inline=“javascript”)和省道(th:inline=“dart”) 使用以下代码段代替如何使用thymeleaf在javascript中使用for循环?,javascript,thymeleaf,Javascript,Thymeleaf,我正在使用thymeleaf,所以当我运行这个应用程序时,它会在(for)(int I=0;I)中给我一个错误*/ 当前的脚本模式是javascript (th:inline=“javascript”)和省道(th:inline=“dart”) 使用以下代码段代替 /**/ 您应该将脚本包装在以下结构中: <script th:inline="javascript"> /*<![CDATA[*/ $( document ).ready(function()
/**/
您应该将脚本包装在以下结构中:
<script th:inline="javascript">
/*<![CDATA[*/
$( document ).ready(function() {
for(i=0;i<10;i++) {
...
}
});
/*]]>*/
</script>
领域
大小
类型
无效的
/**/
我仍然有一个问题,而不是10个问题,我想在我的表格中输入我应该写的列数(inti=0;iYou应该用[[]]
:for(inti=0;i<[${db.columns\u number}]];i++)
你必须更详细。控制台出错?你检查给定的结果以检查返回值吗?很抱歉,所有这些技术对我来说都是新的,所以我努力理解。控制台没有错误,它只给我一个没有行的表,好像他不知道属性db.columns\u numberCheck返回值e在
之前使用此选项:默认值
显示什么?
<script th:inline="javascript">
/*<![CDATA[*/
...
//your code here
...
/*]]>*/
</script>
<script th:inline="javascript">
/*<![CDATA[*/
$( document ).ready(function() {
for(i=0;i<10;i++) {
...
}
});
/*]]>*/
</script>
<tr th:each="i : ${#numbers.sequence( 1, db.columns_number)}">
<td><input id="field" th:name="${'field'+i}" maxlength="255"
required="required" type="text" /></td>
<td><input id="Size" th:name="${'Size'+i}" maxlength="255"
required="required" type="text" /></td>
<td><select id="Type" th:name="${'Type'+i}">
...
</select></td>
<td><select id="null" th:name="${'nullabilite'+i}">
<option value="null">null</option>
<option value="not_null">not_null</option>
</select></td>
</tr>
<table border='1px'>
<thead>
<th>field</th>
<th>Size</th>
<th>Type</th>
<th>null</th>
</thead>
<tbody> </tbody>
</table>
<script th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function () {
for (var i = 0; i < 10; i++) {
var row=[],r=0;
row[r]="<tr>";
row[++r]='<td>';
row[++r]='<input id="field" type="text" name="field"';
row[++r]=i;
row[++r]='maxlength="255" required="required"/>';
row[++r]='</td><td>';
row[++r]='<input id="Size" type="text" name="Size"';
row[++r]=i;
row[++r]= 'maxlength="255" required="required"/>';
row[++r]= '</td>';
/*
* this more readable
* other td
*
*/
row[++r]='</tr>';
$("tbody").append(row.join(""));
}
});
/*]]>*/
</script>