繁体   English   中英

在没有模型的情况下使用 th:object

[英]Using th:object without Model

我想用th:object为数组的每个元素制作表格。但我出错了。 问题是th:object仅用于保存在模型上的对象。 如何在th:each上使用th:objectth:field或任何其他想法来解决它?

<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
       <form th:action="@{'/process/section/save/' + ${sect.id} }" method="post" th:object="${sect}">
          <td>
             <button>
                save
             </button>
          </td>
          <td>
             <input
                 type="text"
                 th:field="*{sect.name}"
                 class="m-inline"
                 placeholder="Страна проведения"/>
          </td>
        </form>
</tr> 

th:field只是设置输入字段的nameidvalue的快捷方式。 你应该能够做到这一点并让它工作:

<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
  <form th:action="@{'/process/section/save/' + ${sect.id}}" method="post">
    <td>
       <button>save</button>
    </td>
    
    <td>
       <input
          type="text"
          name="name"
          th:value="${sect.name}"
          class="m-inline"
          placeholder="Страна проведения" />
    </td>
  </form>
</tr> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM