单选按钮标签更改

问题描述 投票:1回答:1

我需要将单选按钮标签从实际值更改为另一个值

<li th:each="radioValueType: ${type}"><input type="radio"
                                th:field="*{heads[0].type}" th:value="${radioValueType}" /> 
                                <label th:text="${radioValueType}"></label></li>

下面是我的模型属性

    @ModelAttribute("type")
    public ArrayList<Integer> getType(){
         ArrayList <Integer> type = new ArrayList<Integer>();
         type.add(1);
         type.add(5); 
         return type;
    }

但是当我需要展示它时,我需要将它作为'单一'代表5作为'组'。我是thymeleaf的新手

java spring-mvc spring-boot thymeleaf
1个回答
0
投票

最后3小时后发现下面的解决方案是代码

<li th:each="radioValueType: ${type}"><input type="radio"
                            th:field="*{heads[0].type}" th:value="${radioValueType}" /> 
                            <label th:text="( (${radioValueType} == 1)? 'Single' : 'Group')"></label></li>

如果有人遇到同样的麻烦

© www.soinside.com 2019 - 2024. All rights reserved.