现在要实现的目标是根据能耗类型的选择,使下一个下拉菜单网关名称根据选择的能耗类型来筛选,例如我选择能耗类型为“电能表”,那我的网关名称的下拉菜单中的选项中只出现电能表的有关网关名称,如图:
现在我的网关名称“7#青表”就是电能表的网关名称,如果我选择的能耗类型是水表,则网关名称显示的就是对应水表的网关名称
下面介绍js代码:
首先定义一个数组var gateWayStore = new Array();
能耗类型代码
{
fieldLabel : '能耗类型',
name : 'Com.energyType',
id : 'energyType',
xtype : 'combo',
editable : false,//可编辑
emptyText : '请选择',// 默认提示信息
allowBlank : true,
store : etestStore,
displayField : 'energyType',
valueField : 'value',
triggerAction : 'all',
listeners:{
select:function(){
var a=Ext.getCmp('energyType');
var energyType=a.getValue();
Ext.Ajax.request({
method : 'POST',
async : false,
url : __ctxPath + '/console/selectCom.do',//调用Com方法类里的select()方法,根据能耗类型取出网关名称数据
params: {
data:energyType
},
success : function(response){
var data=Ext.util.JSON.decode(response.responseText).data;
for (var i = 0; i < data.length; i++)
{
gateWayStore[i]=data[i].name;
}
var s=Ext.getCmp('GatewayName');
s.store.loadData(gateWayStore);
},
failure : function(response) {
alert("读取数据失败");
},
scope : this
});
}
}
}
网关名称代码:
{
fieldLabel : '网关名称',
name : 'Com.GatewayName',
id : 'GatewayName',
xtype : 'combo',
editable : false,//可编辑
emptyText : '请选择',// 默认提示信息
allowBlank : true,
store : gateWayStore,
displayField : 'GatewayName',
valueField : 'value',
triggerAction : 'all',
},