简体   繁体   English

如何使用百里香叶值传递到引导数据?

[英]how to pass a value using thymeleaf to data of bootstrap?

I want to use Thymeleaf to pass a value to data from Bootstrap. 我想使用Thymeleaf将值传递给Bootstrap中的数据。

I don't know how to do it. 我不知道该怎么做。 Can you help me? 你能帮助我吗?

<tr th:each="car : ${lCars}" class="succes">
  <td th:text="${car.id}"></td>
  <td th:text="${car.name}"></td>
  <td align="center">

    <button type="button" class="btn btn-primary"
      data-toggle="modal" data-target="#editar" title="Edit"
      data-id= "th:text="${car.id}""    <!-- I want to pass this value on to the data, but this way doesn't work -->
      data-name="myCar" <!-- If I send a simple word, works well -->

      <span class="glyphicon glyphicon-pencil"></span> Edit
    </button>
  </td>
</tr>

The following line makes no sense: data-id="th:text="${car.id}"" 以下行没有意义:data-id =“ th:text =” $ {car.id}“”

  1. The purpose of th:text is to modify the body text of the element (in this case, a button element). th:text的目的是修改元素(在本例中为button元素)的主体文本。 You're trying to set an attribute value. 您正在尝试设置属性值。
  2. If you want thymeleaf to modify a data attribute like data-id, you need to th:attr instead 如果要让百里香叶修改数据属性(如data-id),则需要使用th:attr代替

That line should be written as follows: 该行应写为:

data-id="" th:attr="data-id=${car.id}"

If you want the data-id to have some default value like "example-id", do this: 如果您希望data-id具有一些默认值,例如“ example-id”,请执行以下操作:

data-id="example-id" th:attr="data-id=${car.id}"

暂无
暂无

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

相关问题 如何使用 Java 和 Thymeleaf 将变量值传递给 HTML - How to pass a variable value to HTML using Java and Thymeleaf 使用Spring将数据从Thymeleaf传递到控制器 - Pass data from Thymeleaf to the controller using Spring 如何摆脱 org.thymeleaf.exceptions.TemplateInputException: 同时使用 thymeleaf 表达式以引导卡的形式打印数据? - how to get rid of org.thymeleaf.exceptions.TemplateInputException: while using thymeleaf expression to print data in form of bootstrap cards? 如何使用百里香在html中传递对象 - how to pass the object in html using thymeleaf 如何使用 Bootstrap 和 thymeleaf 在模态内的表单中填充值? - How can I populate value at form inside modal using Bootstrap and thymeleaf? 如何使用类似于JSP的Thymeleaf将表单数据从一个HTML传递到另一HTML? - How do I pass form data from one HTML to another using Thymeleaf similar to JSP? 如何将setter值直接传递到网页(百里香)? - How to pass setter value directly to web page (thymeleaf)? Thymeleaf表单验证唯一值,如何将错误传递给查看 - Thymeleaf form validation for unique value, how to pass error to view 如何使用 Thymeleaf 和 Bootstrap 显示 Spring 中的所有枚举值 - How to display all enum values in Spring using Thymeleaf and Bootstrap 如何在 Spring Boot 中使用 Thymeleaf 将值传递给 HTML 模板的变量 - How to pass values to variables of a HTML template using Thymeleaf in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM