ext combobox动态加载数据库数据(附前后台)
投稿:whsnow
这篇文章主要介绍了ext combobox动态加载数据库数据并附前后台实现,需要的朋友可以参考下
前台:
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"]
)
});
//选择省市
var provinceIDadd = new Ext.form.ComboBox({
anchor : '98%',
id:'provinceIDadd',
name : "provinceIDAdd1",
hiddenName : "provinceID",
displayField : "PROVINCENAME",
valueField : "PROVINCEID",
blankText : '请选择站点所属省份',
emptyText : '请选择站点所属省份',
fieldLabel : '站点所属省份',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :provinceStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})
provinceStore.load();
后台action代码
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配置
<result name="json_getProvinceList" type="json" >
<param name="root">provinceList</param>
</result>
加载静态数据的下拉选择框
var dataType=[['0','8列'],['1','38列'],['2','21列']];
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 : '请选择数据格式',
emptyText : '请选择数据格式',
fieldLabel : '数据格式',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :unitStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})
复制代码 代码如下:
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"]
)
});
//选择省市
var provinceIDadd = new Ext.form.ComboBox({
anchor : '98%',
id:'provinceIDadd',
name : "provinceIDAdd1",
hiddenName : "provinceID",
displayField : "PROVINCENAME",
valueField : "PROVINCEID",
blankText : '请选择站点所属省份',
emptyText : '请选择站点所属省份',
fieldLabel : '站点所属省份',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :provinceStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})
provinceStore.load();
后台action代码
复制代码 代码如下:
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配置
复制代码 代码如下:
<result name="json_getProvinceList" type="json" >
<param name="root">provinceList</param>
</result>
加载静态数据的下拉选择框
复制代码 代码如下:
var dataType=[['0','8列'],['1','38列'],['2','21列']];
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 : '请选择数据格式',
emptyText : '请选择数据格式',
fieldLabel : '数据格式',
allowBlank : false,
editable : false,
triggerAction : 'all',
store :unitStore ,
forceSelection : true,
mode : 'local',
selectOnFocus : true
})