javascript - thymeleaf 表达式

标签 javascript jquery html spring-boot thymeleaf

我在 Thymeleaf 页面中有这段代码,我想在其中获得类似 selectAuthorizedDriver1,selectAuthorizedDriver2,... 的内容

我尝试过

<tr th:each="item: ${devices}" >
    <select th:id="selectAuthorizedDriver${item.id}" >

<tr th:each="item: ${devices}" >
    <select id="selectAuthorizedDriver${item.id}" >

还有

<tr th:each="item: ${devices}" >
    <select th:id="selectAuthorizedDriver${id}(id=${item.id})" >

但是我得到了错误:

 Could not parse as expression: "selectAuthorizedDriver${item.id}" 

或字面上的“selectAuthorizedDriver${item.id}”

最佳答案

对于只需要字符串的表达式,您可以将它们附加在一起。在您的示例中:

<tr th:each="item: ${devices}" >
    <select th:id="${'selectAuthorizedDriver' + item.id}">

您还可以使用 preprocessing 来完成此操作,但在本例中不需要。 (如果您需要编写 th:field 表达式,则必须这样做)。

<tr th:each="item: ${devices}" >
    <select th:id="${'selectAuthorizedDriver__${item.id}__'}">

关于javascript - thymeleaf 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48499509/

相关文章:

javascript - 通过单击 html 中的特定按钮转到特定选项卡

javascript - 在 Html/Javascript 中第二次用相同的路径替换图像不起作用

javascript - 从顶层到底层对 DOM 节点数组进行排序

javascript - 将单个字符字体缩放到其父 div

javascript - 类构造函数 super() 在 IE 中不起作用

javascript - 根据另一个元素的数据属性隐藏一个元素

javascript - jQuery ContextMenu 事件在 IOS 8.2 中不起作用

javascript - 翻译 Api/后端错误消息以向用户显示

css - 页面上的中心按钮

javascript - 在javascript中使用鼠标坐标,如何适应不同的屏幕尺寸?