Ext combobox dynamically loads database data of with front and background
- 2020-03-30 03:22:22
- OfStack
Front desk:
Background action code
Strtus XML configuration
Load the drop-down selection box for static data
var provinceStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: basePath + "/stationManage/station_getProvinceJSON.action" }),
reader: new Ext.data.JsonReader(
{ root: "" },
["PROVINCEID", "PROVINCENAME"]
)
});
//Select provinces and cities
var provinceIDadd = new Ext.form.ComboBox({
anchor : '98%',
id:'provinceIDadd',
name : "provinceIDAdd1",
hiddenName : "provinceID",
displayField : "PROVINCENAME",
valueField : "PROVINCEID",
blankText : ' Please select the province of the site ',
emptyText : ' Please select the province of the site ',
fieldLabel : ' Province of the site ',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :provinceStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})
provinceStore.load();
Background action code
public class StationAction extends BaseAction {
private List<Map<String, Object>> provinceList;
public void setProvinceList(List<Map<String, Object>> provinceList) {
this.provinceList = provinceList;
}
public List<Map<String, Object>> getProvinceList() {
return provinceList;
}
public String getProvinceJSON(){
String sql="SELECT PK_ID PROVINCEID,NAME PROVINCENAME FROM T_DICT_DISTRICT A WHERE A.DISTRICT_LEVEL=20";
provinceList= stationService.findBySQL(sql);
return "json_getProvinceList";
}
}
Strtus XML configuration
<result name="json_getProvinceList" type="json" >
<param name="root">provinceList</param>
</result>
Load the drop-down selection box for static data
var dataType=[['0','8 column '],['1','38 column '],['2','21 column ']];
var dataTypeStore = new Ext.data.SimpleStore({
fields: ['dataTypeID', 'dataTypeName'],
data : data
});
var dataTypedd = new Ext.form.ComboBox({
anchor : '98%',
id:'dataTypeadd',
name : "dataTypeAdd1",
hiddenName : "dataType",
displayField : "dataTypeName",
valueField : "dataTypeID",
blankText : ' Please select the data format ',
emptyText : ' Please select the data format ',
fieldLabel : ' The data format ',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :unitStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})