直接上代码案例:
//临时联动------------------------------------------------------------------
//创建一级数据源
var combocitystoreA = new Ext.data.Store({
//设定读取的地址
proxy: new Ext.data.HttpProxy({ url: 'ContractAction.asp?method=classPc1&authoriseId=10207002' }),
//设定读取的格式
reader: new Ext.data.JsonReader({ root: 'data' },
[{ name: 'id' }, { name: 'name'}])
});
//创建二级数据源
var comboareastoreA = new Ext.data.Store({
//设定读取的地址
proxy: new Ext.data.HttpProxy({ url: 'ContractAction.asp?method=classPc2&authoriseId=10207004' }),
reader: new Ext.data.JsonReader({ root: 'data' },
[{ name: 'id' }, { name: 'name'}])
});
//创建三级数据源
var combocountystoreA = new Ext.data.Store({
//设定读取的地址
proxy: new Ext.data.HttpProxy({ url: 'ContractAction.asp?method=classPc3&authoriseId=10207004' }),
reader: new Ext.data.JsonReader({ root: 'data' },
[{ name: 'id' }, { name: 'name'}])
});
//创建市Combobox
var comboboxcityA = new Ext.form.ComboBox({
anchor :'86%',
id: 'pc1',
name:'pc1',
fieldLabel: '行业主分类',
// width: 100,
store: combocitystoreA,
displayField: 'name',
valueField: 'id',
triggerAction: 'all',
emptyText: '请选择...',
allowBlank: false,
blankText: '请选择主分类',
editable: false,
mode: 'local', //该属性和以下方法为了兼容ie8
listeners: {
'render': function () {
combocitystoreA.load();
}
}
});
//创建区Combobox
var comboareacityA = new Ext.form.ComboBox({
fieldLabel: '二级分类',
// width: 100,
anchor :'86%',
id:'pc2',
name:'pc2',
store: comboareastoreA,
displayField: 'name',
valueField: 'id',
triggerAction: 'all',
emptyText: '请选择...',
allowBlank: false,
blankText: '请选择二级分类',
editable: false
});
//创建县城Combobox
var combocountycityA = new Ext.form.ComboBox({
fieldLabel: '三级分类',
//width: 100,
anchor :'86%',
id:'pc3',
name:'pc3',
store: combocountystoreA,
displayField: 'name',
valueField: 'id',
triggerAction: 'all',
emptyText: '请选择...',
allowBlank: false,
blankText: '请选择三级分类',
editable: false
});
//联动的实现
comboboxcityA.on('select', function () {
comboareastoreA.baseParams.id = comboboxcityA.getValue();
comboareacityA.setValue('');
comboareastoreA.load();
});
comboareacityA.on('select', function () {
combocountystoreA.baseParams.id = comboareacityA.getValue();
combocountycityA.setValue('');
combocountystoreA.load();
});