Ajax 如何根据国家/地区组合框中的国家/地区选择动态生成组合框?
我有一个从数据库中获取countryname列表的方法,还有一个为任何提供的countryname获取StateName的方法。但不知道如何将国家和州联系起来Ajax 如何根据国家/地区组合框中的国家/地区选择动态生成组合框?,ajax,autocomplete,struts2,Ajax,Autocomplete,Struts2,我有一个从数据库中获取countryname列表的方法,还有一个为任何提供的countryname获取StateName的方法。但不知道如何将国家和州联系起来 <sx:autocompleter list="countrynames" name="employee.countryname" value="%{employee.countryname}" label="%{getText('label.countryname')}"/> <sx:autocomp
<sx:autocompleter list="countrynames" name="employee.countryname" value="%{employee.countryname}" label="%{getText('label.countryname')}"/>
<sx:autocompleter list="statenames" name="employee.statename" value="%{employee.statename}" label="%{getText('label.statename')}"/>
我拥有名为“countryname”和类似“StateName”的ArrayList,但不确定如何根据上述国家/地区列表中国家/地区的选择动态生成国家/地区名称,以及如何将获取的国家/地区名称连接到显式调用该国/地区国家/地区列表的方法 我想给你一些建议
function fill statenames(countryID)
var formInput='country='+countryID;
$.getJSON('search/getStateNames',formInput,function(data) {
$("#employee.statename option:first").val("-1").text("Please select state");
$('.result').html('' + data.states + '');
$.each(data.states ,function(index, value){
var stateid= document.getElementById("state");
var option=new Option(value,value);
try{
stateid.add(option);
}
catch(e){
stateid.appendChild(option);
}
});
});
动作类
公共类StateListAction扩展了ActionSupport{
私人国家;
//接二连三
私人名单国家;
//接二连三
公共字符串getStateList(){
州=填写StateBasedOnCountry(国家);
回归成功;
}
}
public class StateListAction extends ActionSupport{
private String country;
// getter and setter
private List<String> states;
//getter and setter
public String getStateList(){
states=fillStatebasedonCountry(country);
return SUCCESS;
}
}