很多表单中都用到了下拉列表.比如 某人属于哪个国家.
"国家"做为下拉列表表现出来
在 grid 中列出来的样式
姓名 国家
--------------
张三 中国
Jack 美国
当点击上述某一列的时候 在表单中表现为
姓名:张三
国家:<这里是一个下拉列表,默认选中'中国'>
下面是代码
public class User extends BaseModel implements IsSerializable{
/**
*
*/
private static final long serialVersionUID = -4078159040998522187L;
private String userName;
private Country country;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
//这里通过GXT提供的'set'方法进行set值
country.set("name", country.getName());
this.country = country;
}
}
public class Country extends BaseModel implements IsSerializable{
/**
*
*/
private static final long serialVersionUID = -1888971993117554920L;
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
下面是页面代码
ComboBox<Country> combo = new ComboBox<Country>();
combo.setFieldLabel("国家");
combo.setName("country");
combo.setEmptyText("请选择国家");
combo.setDisplayField("name");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(countryStore);
combo.setAllowBlank(false);
其实就是对GXT model 的 set 和 get 方面的使用