最近用到了 ComboBox 和 Radio 在网上找了写例子看了下,但是出不了效果,后来自己研究了一下,终于出效果了,现在记录一下:
ComboBox ;
ListStore<BaseModel> merchantStore = new ListStore<BaseModel>();
merchantStore.add(getType());
ComboBox<BaseModel> merchant = new ComboBox<BaseModel>();
merchant.setFieldLabel("商户:");
merchant.setDisplayField("type");
merchant.setEmptyText("==Select==");
merchant.setStore(merchantStore);
merchant.setTypeAhead(true);
merchant.setTriggerAction(TriggerAction.ALL);
formPanel.add(merchant, new FormData("100%"));
private List<BaseModel> getType() {
List<BaseModel> list = new ArrayList<BaseModel>();
list = new ArrayList<BaseModel>();
BaseModel bm = new BaseModel();
bm.set("type", "猫类");
bm.set("key",1);
list.add(bm);
bm = new BaseModel();
bm.set("type", "狗类");
bm.set("key",2);
list.add(bm);
bm = new BaseModel();
bm.set("type", "鸟类");
bm.set("key",3);
list.add(bm);
bm = new BaseModel();
bm.set("type", "其他");
bm.set("key",4);
list.add(bm);
return list;
}
取值:
types.addListener(Events.Change, new Listener<ComponentEvent>(){
public void handleEvent(ComponentEvent be) {
ComboBox<BaseModel> selectBox = (ComboBox) be.getComponent();
type = selectBox.getValue().get("type");
}
});
Radio :
final RadioGroup group = new RadioGroup();
group.setFieldLabel("宠物性别");
Radio first = new Radio();
first.setData("key", 1);
first.setBoxLabel("雄性");
first.setValue(true);
group.add(first);
Radio second = new Radio();
second.setData("key", 2);
second.setBoxLabel("雌性");
group.add(second);
formPanel.add(group, new FormData("100%"));
取值;
group.addListener(Events.Change, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
RadioGroup selectedRadioGroup = (RadioGroup) ((FieldEvent) be).getComponent();
String haha = selectedRadioGroup.getValue().getData("key")+"";
if(haha.equals("1")){
sex = "雄性";
}
if(haha.equals("2")){
sex = "雌性";
}
}
});