我如何在使用百里香的javascript中使用for循环? [英] How can i use for loop in javascript using thymeleaf?

查看:56
本文介绍了我如何在使用百里香的javascript中使用for循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用百里香叶,所以当我运行此应用程序时,它给我一个错误(for(int i = 0; i< 10; i ++)),这意味着我必须尊重百里香叶的语法.我的问题是如何我使用百里香叶编写了此脚本.

I am using thymeleaf so when I run this application ,it gives me an error in (for(int i=0;i<10;i++) It means I have to respect the syntaxe of thymeleaf.My question is howa can I write this script using thymeleaf.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Handing Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
        <script type="text/javascript" src="jquery-1.11.3.js"></script>

</head>
<body>
    <h1>Result</h1>
    <p th:text="'columns_number: ' + ${db.columns_number}" />
    <h3>Création de la base de données</h3>
    <p>Table_name: <input type="text" th:field="${db.table_Name}" /></p>
<table id='tablona' border='1px'>
        <tr>
        <th>field</th>
                <th>Size</th>
                <th>Type</th>
                <th>null</th>
                </tr>


</table>

<script th:inline="javascript">
    /*<![CDATA[*/
    $( document ).ready(function() {

        for(int i=0;i<[[${T(Integer).parseInt(db.columns_number)}]];i++)
      {
        $('<tr>'+
        '<td><input id="field" type="text" name="field'+i+'"  maxlength="255"  required="required"/></td>'+
        '<td><input id="Size" type="text"  name="Size'+i+'"  maxlength="255" required="required"/></td>'+
        '<td><SELECT id="Type" name="Type'+i+'">'+
'<OPTION VALUE="varchar">varchar</OPTION>'+
'<OPTION VALUE="int">int</OPTION>'+
'<OPTION VALUE="text">long</OPTION>'+
'<OPTION VALUE="float">float</OPTION>'+
'<OPTION VALUE="double">double</OPTION>'+
'<OPTION VALUE="Date">Date</OPTION>'+
'<OPTION VALUE="Time">Time</OPTION>'+
'<OPTION VALUE="Year">Year</OPTION>'+
'<OPTION VALUE="Real">Real</OPTION>'+
'<OPTION VALUE="Boolean">Boolean</OPTION>'+
'<OPTION VALUE="longText">longText</OPTION>'+
'<OPTION VALUE="Binary">Binary</OPTION>'+
'</SELECT></td>'+
'<td><SELECT id="null" name="nullabilite'+i+'">'+
'<OPTION VALUE="null">null</OPTION>'+
'<OPTION VALUE="not_null">not_null</OPTION>'+
'</SELECT></td>'+
    '</tr>').appendTo($("#tablona")).html()

    }
    });
    /*]]>*/
</script>
      <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>    

</body>
</html> 

推荐答案

您应将脚本包装在以下结构中:

You should wrap your script in this structure :

<script th:inline="javascript">
    /*<![CDATA[*/
    $( document ).ready(function() {
        for(i=0;i<10;i++) {
            ...
        }
    });
    /*]]>*/
</script>

别忘了将javascript和其他静态文件存储在spring-boot项目的/src/main/webapp 文件夹中

Don't forget to store your javascript and other static files in the /src/main/webapp folder of your spring-boot project

您可以直接用thymeleaf编写脚本:

You can do directly your script with thymeleaf :

<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>

这篇关于我如何在使用百里香的javascript中使用for循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆