【发布时间】:2021-05-18 22:23:51
【问题描述】:
我的选择有文档类型、年份和月份,我的文档类型包括月度报告和年度报告
但是如果我的文档类型选择为“年度报告”,我想隐藏“月”选项,因为年度报告是基于年度的。如何将这样的 if 语句放入我的 html 中?
百里香html
<table class="table table-borderless" cellspacing="0"
style="border-inline: 0;">
<tbody>
<div th:if="${user!=null}">
<tr>
<!-- Document Type -->
<td th:text="#{DocType}" />
<td colspan="1">
<div class="dropdown col-sm-6">
<select id="documentType" class="browser-default custom-select"
th:field="*{type}">
<option
th:each="doc:${T(enums.DocumentType).values()}"
th:value="${doc}" th:text="${doc.label}"></option>
</select>
</div>
</td>
</tr></div>
<tr>
<!-- YEAR -->
<td th:text="#{Year}" />
<td colspan="1">
<div class="dropdown col-sm-6">
<select class="browser-default custom-select" th:field="*{year}">
<option value="">Please Select</option>
<option th:each="year : ${years}" th:value="${year}"
th:text="${year}"></option>
</select>
</div>
</td>
</tr>
<tr>
<!-- MONTH -->
<td th:text="#{Month}" />
<td colspan="1">
<div class="dropdown col-sm-6">
<select class="browser-default custom-select" th:field="*{month}">
<option value="">Please Select</option>
<option th:each="month : ${months}" th:value="${month}"
th:text="${month}"></option>
</select>
</div>
</td>
</tr>
</tbody>
</table>
DocumentType.java
public enum DocumentType {
MONTHLY("MONTHLY", "Monthly Report"),
ANNUAL("ANNUAL", "Annual Report"),
private String code;
private String label;
DocumentType(final String code, final String label) {
this.code = code;
this.label = label;
}
public String getCode() {
return code;
}
public String getLabel() {
return label;
}
}
【问题讨论】:
-
如果对你有帮助,你可以接受我的回答