java - Thymeleaf 显示列表对象的字段

标签 java spring spring-boot spring-mvc thymeleaf

我有

<table style="padding-top: 15px; padding-left: 50px; width: 1366px;">
    <tr>
        <thead>
        <th>STT</th>
        <th width="24%">Số tài khoản</th>
        <th width="24%">Tên ngân hàng</th>
        <th width="24%">Chi nhánh</th>
        <th width="24%">Tỉnh/TP của ngân hàng</th>
        </thead>
        <tbody>
        <tr th:each="item, itemStat : ${accountObjectForm.accountObjectBankAccountList}">
            <td><span th:text="${itemStat.index + 1}"></span></td>
            <td><input type="text" th:value="${accountObjectForm.accountObjectBankAccountList[0].bankAccount}" th:name="|accountObjectBankAccountList[${itemStat.index}].bankAccount|" th:id="|accountObjectBankAccountList[${itemStat.index}].bankAccount|" class="k-textbox" style="width: 100%;"></td>
            <td><input type="number" th:name="|accountObjectBankAccountList[${itemStat.index}].bankId|" th:id="|accountObjectBankAccountList[${itemStat.index}].bankId|" class="k-textbox" style="width: 100%"></td>
            <td><input type="text" th:name="|accountObjectBankAccountList[${itemStat.index}].bankBranchName|" th:id="|accountObjectBankAccountList[${itemStat.index}].bankBranchName|" class="k-textbox" style="width: 100%;"></td>
            <td><input type="text" th:name="|accountObjectBankAccountList[${itemStat.index}].province|" th:id="|accountObjectBankAccountList[${itemStat.index}].province|" class="k-textbox" style="width: 100%;"></td>
        </tr>
        <script>
            $(document).ready(function () {
                var dataBank = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: "/banks_json",
                            dataType: "json"
                        }
                    },
                    pageSize: 30
                });

                $("input[name$='bankId']").each(function() {
                    $(this).kendoDropDownList({
                        optionLabel: "Chọn...",
                        dataTextField: "bankCode",
                        dataValueField: "id",
                        dataSource: dataBank,
                        index: 0,
                        change: onChangeBank
                    })
                });

                var dataProvinceBank = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: "/provinces",
                            dataType: "json"
                        }
                    },
                    pageSize: 300
                });

                $("input[name$='province']").each(function() {
                    $(this).kendoDropDownList({
                        optionLabel: "Chọn...",
                        dataTextField: "text",
                        dataValueField: "value",
                        filter: "contains",
                        dataSource: dataProvinceBank,
                        index: 0,
                        change: onChangeProvinceBank
                    })
                });
            });
            function onChangeBank() { }
            function onChangeProvinceBank() { }
        </script>
        </tbody>
    </tr>
</table>

结果 enter image description here

(在新选项卡中打开图像以查看更大的屏幕截图)

在引擎盖下 enter image description here

我试试

<td><input type="text" th:value="${accountObjectForm.accountObjectBankAccountList[${itemStat.index}].bankAccount}" th:name="|accountObjectBankAccountList[${itemStat.index}].bankAccount|" th:id="|accountObjectBankAccountList[${itemStat.index}].bankAccount|" class="k-textbox" style="width: 100%;"></td>

但是错误,当捕获这些代码行时,页面无法渲染为 html。

我使用 0 作为支架。请帮我通过列表索引更改数字0

th:value="${accountObjectForm.accountObjectBankAccountList[0].bankAccount}"

最佳答案

省略表达式中的内部${...}大括号,直接引用itemStat.index。您已经在使用 thymeleaf 表达式语法,无需使用两次。

不确定这是否是您的代码的唯一问题,但肯定首先要修复

关于java - Thymeleaf 显示列表对象的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56912986/

相关文章:

java - Spring Boot 和 Teradata UnsatisfiedDependencyException

html - 存储在 "/images"目录中的静态内容未被提供,因为 URL 相对于“/css”目录

Spring Boot @Aspect 日志记录

java - Eclipse 声称我没有名为 R.id.list 的 ListView

java - 将图像放入包中

Java - 在 Switch Case 中调用另一个输入方法

java - REST 端点在 AWS 与 localhost 中返回不同的结果

java.lang.ClassCastException : net. sf.ehcache.hibernate.SingletonEhCacheRegionFactory 无法转换为 org.hibernate.cache.RegionFactory

spring - 通过@Bean 提供的 RestTemplateBuilder 流式上传缓冲完整文件

java - 奇怪的 EDT 违规,不包含我的代码