2017-06-21 562 views
2

我有這樣一段代碼在我Thymeleaf模板,但它不能正常工作,因爲這是window.location.href上thymeleaf

deviceevent/@%7B/deviceevent/list/%7Bid%7D(id=$%7BdeviceEvent.id%7D)%7D 

模板生成的位置

<tr th:each="deviceEvent : ${deviceEvents}" onclick="window.location.href = '@{/deviceevent/list/{id}(id=${deviceEvent.id})}'" > 

回答

4

Thymeleaf不會評估屬性,除非它們的前綴爲th。在這種情況下,th:onclick。完整的字符串應該看起來像這樣:

th:onclick="'window.location.href = \'' + @{/deviceevent/list/{id}(id=${deviceEvent.id})} + '\''" 
+0

非常感謝 – makson