【发布时间】:2022-01-20 17:40:35
【问题描述】:
在我的页面上,我有一个评论列表,每个评论都有一些 cmets。
从我的后端,我得到了所有评论的列表,以及所有 cmets 的列表。
每条评论都有review 属性,它决定了它所属的评论。
在每条评论下,我现在都在尝试展示相关的 cmets。
为此,我试图从我的comments 列表中过滤和循环所有 cmets,其中它们的父评论 (comment.review.getID()) 的 ID 等于当前评论的 ID (review.getID())。
这是我尝试的方法,但它不起作用。:
<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(或与局部变量 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 变量。
我该怎么做?
【问题讨论】: