如何使用Spring 4 Boot + ThymeLeaf + Hibernate基于另一个选择框的选择来填充选择框

时间:2016-05-24 04:14:11

标签: spring thymeleaf

我正在创建一个注册表单,我必须创建三个选择框。第一个选择框包含所有国家/地区,根据选择状态选择框变为可见,并且仅显示特定选定国家/地区可用的状态。此外,还有城市选择框,默认情况下,城市下拉列表在选择状态之前不会显示,并且根据选择,仅显示属于选择状态选择框中的特定状态的城市。

我能够生成所有选择框,但是如何基于选择进行过滤,我真的不知道。

努力:

<div class="form-group">
    <label th:text="#{register.label.country}" `class="col-md-4 control-label">Country:</label>
    <div class="col-md-6">
        <select class="form-control" th:field="*{address.country}">
            <option value="-1">--- Select Country ---</option>
            <option th:each="country : *{countries}" th:value="${country.configId}" th:text="${country.configName}"></option>
        </select>
        <strong th:if="${#fields.hasErrors('address.country')}" th:errors="*{address.country}">Country Error</strong>
    </div>
</div>
<div class="form-group">
    <label th:text="#{register.label.state}" class="col-md-4 control-label">State:</label>
    <div class="col-md-6">
        <select class="form-control" th:field="*{address.state}">
            <option value="-1">--- Select State ---</option>
            <option th:each="state : *{states.?[parentid = 1]}" th:value="${state.configId}" th:text="${state.configName}"></option>
        </select>
        <strong th:if="${#fields.hasErrors('address.state')}" th:errors="*{address.state}">Country Error</strong>
    </div>
</div>
<div class="form-group">
    <label th:text="#{register.label.city}" class="col-md-4 control-label">City:</label>
    <div class="col-md-6">
        <select class="form-control" th:field="*{address.city}">
            <option value="-1">--- Select City ---</option>
            <option th:each="city : *{cities}" th:value="${city.configId}" th:text="${city.configName}"></option>
        </select>
        <strong th:if="${#fields.hasErrors('address.city')}" th:errors="*{address.city}">Country Error</strong>
    </div>
</div>

我能够生成所有选择框,但我真的不知道如何基于Spring启动的百里香的选择来生成。

请帮帮我。我知道我可以通过使用jquery ajax来做到这一点,但是我想避免,我的意思是它可能与百里香本身有关。

1 个答案:

答案 0 :(得分:0)

Thymeleaf是服务器端的Web模板引擎。 一旦呈现并显示给客户端,Thymeleaf就不再存在了。 处理它的唯一方法是通过javascript;或者通过发送新的请求来呈现新的过滤选项。

相关问题