您的当前位置:首页正文

extcombobox动态加载数据库数据(附前后台)_extjs

2022-06-15 来源:知库网

前台:
代码如下:
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> provinceList;
public void setProvinceList(List> provinceList) {
this.provinceList = provinceList;
}

public List> 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配置
代码如下:

provinceList


加载静态数据的下拉选择框
代码如下:
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
})

显示全文