2014-12-24 52 views
0

以我當前彈簧項目,其中一個視圖已在thymeleaf代碼以下:Thymeleaf:條件表達式不評估

<div class="input-group" th:each="item : ${role}" th:id="${item.getId()}"> 
    <span class="input-group-addon" th:with="possui = 'not'"> 
     <span th:each="item2 : ${usuario.getRole()}" th:if="${item.getId() == item2.getId()}" th:with="possui = 'yes'" class="glyphicon glyphicon-check" th:id="icon__${item.getId()}__" aria-hidden="true"></span> 
     <span th:if="possui == 'not'" class="glyphicon glyphicon-unchecked" th:id="icon__${item.getId()}__" aria-hidden="true"></span> 
    </span> 

    <input type="text" class="form-control" th:value="${item.getNome()}" disabled="disabled"/> 

    <span class="input-group-btn"> 
     <button class="btn btn-default" th:attr="data-id=${item.getId()}" type="button"> 
     <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 
     </button> 
    </span> 
    </div> 

在第一塊從input-group(具有類input-group-addon),應如果用戶有角色則顯示選中的圖標,如果用戶沒有,則顯示未選中的圖標。但對於上面的代碼,只顯示選中的圖標。

任何人都可以看到這段代碼有什麼問題?

回答

2
<span th:if="possui == 'not'" class="glyphicon glyphicon-unchecked" th:id="icon__${item.getId()}__" aria-hidden="true"></span> 

應該

<span th:if="${possui == 'not'}" class="glyphicon glyphicon-unchecked" th:id="icon__${item.getId()}__" aria-hidden="true"></span> 

通知的${possui == 'not'}

提示:${item.getId()},您可以使用${item.id}

+0

這個sugestion,正確顯示選中的圖標,但選中圖標顯示列表中的所有項目。 –

+0

@KleberMota我只查看了你的代碼的語法,這樣複雜的條件不應該在前面實現,把它放在java代碼上。它會更清楚 – Jaiwo99