开发者

playframework: dropdownlist selected value

开发者 https://www.devze.com 2023-03-31 13:45 出处:网络
How to pass a value from one dropdown to a second dropdown. 开发者_运维百科Example: Template #{select \'pl\'}

How to pass a value from one dropdown to a second dropdown.

开发者_运维百科

Example:

Template

#{select 'pl'}

            #{list platforms, as: 'platform'}
                #{option}${platform.description} #{/option}
            #{/list}
#{/select}                          


 #{select 'pl'}        
        #{list cdrs, as:'cdr'}
               #{option}${cdr.description} #{/option}
        #{/lisst}          
 #{/select}        


If you mean using Javascript to "chain" two selects like Country/City, what I did was moving the code for the second select to its own view (e.g. Cities/selectCities.html)

#{select 'city', items: cities, valueProperty: 'id', labelProperty: 'name' /}

and use an include in the view where I'll have both chained selects

<select name="country" id="select-country">
    <option value="ES">Spain</option>
    <option value="US">United States</option>
</select>

<span id="select-city">
    #{include 'Cities/selectCities.html' /}
</span>

now some javascript in that same view to reaload second select in case first select changes

$('#select-country').change(function() {
    var selectAction = #{jsAction @reloadCities(':country') /};
    $('#select-cities').load(selectAction({country: $(this).val()}));
});

and in the controller we have our reaload cities method rendering only the second select again

public static void reloadCities(String country) {
    List<City> cities = City.find("byCountryCode", country).fetch();

    render("@selectCities", cities);
}

and that's about it, for me it's working using play 1.2.5


Your question is not really clear but if I understand it right, you want to change a select depending on the value of the selected item in the first select. That is impossible as it is a runtime animation.

You will have to take a look at Ajax/Javascript in order to do things like that.


If you mean once is rendered in the browser, you must use Javascript.

Otherwise, use the value keyword as explained in the documentation (here)

0

精彩评论

暂无评论...
验证码 换一张
取 消