EXTJS三级联动

本文介绍如何使用 ExtJS 创建具有三级联动功能的 ComboBox 组件,并展示了具体的 JavaScript 代码实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上代码案例:

	//临时联动------------------------------------------------------------------

	 //创建一级数据源
    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();
    });
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值