在我的頁面上,我有一個評論串列,每個評論都有一些評論。從我的后端,我得到了所有評論的串列和所有評論的串列。每個評論都有review屬性,它決定了它所屬的評論。
在每條評論下,我現在都試圖展示相關的評論。為此,我試圖過濾并回圈遍歷comments串列中的所有評論,其中它們的父評論 ( comment.review.getID()) 的 ID 等于當前評論 ( review.getID()) 的 ID。
這就是我正在嘗試的方式,但它不起作用。:
<div class="review" th:each="review : ${reviews}">
<div class="review-comments" th:with="reviewID=${review.getID()}">
<div class="comment" th:each="comment : ${comments.?[#this.review.getID() eq reviewID]}">
它拋出這個錯誤:
Property or field 'reviewID' cannot be found on object of type 'de.firefuro.forum.entity.Comment'
那么如何將評論的評論 ID 與區域變數reviewID(或與 local review.getID())進行比較?
我也試過
<div class="review" th:each="review : ${reviews}">
<div class="review-comments">
<div class="comment" th:each="comment : ${comments.?[#this.review.getID() eq review.getID()]}">
但這也不起作用。它沒有過濾任何東西。可能是因為它認為review我的意思是comment.review。我無法設法使用區域review變數。
我該怎么做?
uj5u.com熱心網友回復:
假設Comment該類有content欄位,我想這將是正確的語法:
<div th:each="review : ${reviews}">
<div th:text="${review.id}"></div>
<div th:each="comment : ${comments.?[review.id == __${review.id}__]}">
<div th:text="${comment.content}"></div>
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/417592.html
標籤:
