html - 组合框中带有百里香叶的默认值
问题描述
我有百里香叶的问题。我有一个带有组合框和一些字段的表单。我想将默认值放在组合框中,并且“选择”的子句对我不起作用。
代码是这样的:
<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">
<option value="" th:text="#{select.option.default}"> </option>
<option th:each="row : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="#{${row==2}}"></option>
</select>
其中“tipoDocumento”是一个具有两个值的枚举:
public enum TipoDocumento {
PUBLICO("documento.tipo.publico"),
PRIVADO("documento.tipo.privado");
private String property;
private String value;
private TipoDocumento(String property) {
this(property, null);
}
private TipoDocumento(String value, String property) {
this.value = value;
this.property = property;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
}
有人能帮我吗?
解决方案
选定的标签应该可以工作。请记住,它需要像selected="selected"
. 我已经在几个选择中使用它并且它总是有效的。此外,th:each
您需要删除该th:selected="#{${row==2}}"
元素,否则您的第一个选项将不是默认选项。
<select class="dsp-inline form-control" required="required" th:disabled="${permisoXestion == false}">
<option value="" th:text="#{select.option.default}"></option>
<option th:each="row, iter : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="${iter.count eq 2} ? 'selected' : 'false'"></option>
</select>
推荐阅读
- python - Python CV2 颜色检测混淆
- algorithm - UTXO选择策略
- reactjs - 使用从父组件中进行的异步 api 调用接收的道具更新反应子组件的状态
- php - 未排序的数组 - 从下一个更高的值获取索引 | 复杂度 O(n), PHP
- javascript - 如何只允许粘贴输入中的 URL?
- python - 如何在 python 中正确重塑 ConvLSTM 的数据?
- javascript - onDeviceChange() 仅在 macOS Chrome 中正常工作
- excel - 在行或范围函数内使用变量的语法?
- python - How to merge values with same keys in a nested dictionary? (Nothing works)
- windows - OpenGL gl::GetUniformLocation 仅在某些情况下无法定位统一