ExtJS4.2 下拉列表Combobox级联选择

本文主要讲解了如何实现ExtJS4.2中下拉列表(Combobox)的级联选择,即先选择省份,自动将城市过过滤为该省份下的城市列表,实例图片如:
20140817009.png

在线演示  /  示例代码


省份-下拉列表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
                    xtype:'combo',
                    id:'provinceCombo',
                    labelStyle : 'text-align:right',
                    fieldLabel: '省',
                                displayField: 'text',
                                valueField: 'value',
                                store: createStore(),
                                editable : false,
                                queryMode: 'local',
                                typeAhead: true,
                                listeners: {
                                    change: function(combo, nv, ov){
                                        if(nv!=ov){
                                        var cityCombo = Ext.getCmp("cityCombo");
                                        cityCombo.clearValue();
                                        
                                        var cityStore=cityCombo.getStore();
                                        cityStore.load();
                                      }
                                    }
                                }
                }


城市
-下拉列表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
                xtype: 'container',
                flex: 1,
                layout: 'anchor',
                items: [{
                    xtype:'combo',
                    id:'cityCombo',
                    labelStyle : 'text-align:right',
                    fieldLabel: '市',
                    editable : false,
                    displayField: 'text',
                    valueField: 'value',
                    store: 'CityStore',
                    queryMode: 'remote',
                    typeAhead: true
                }]
            }


城市下拉列表对应的Store-CityStore:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Ext.define('Itdatum.store.CityStore', {
    extend: 'Ext.data.Store',
    fields:['id','value','text','parentid'],
    autoLoad: false,
    proxy: {
      type: "ajax",
      url: "json/city.json",
      reader: {
        type: "json",
        root: "data"
      }
   },
   listeners: {
            'load': function(store, operation, eOpts){
                var proviceCode=Ext.getCmp('provinceCombo').getValue();
                store.filterBy(function(record) {
                    return record.get('parentid') == proviceCode;  
                });
            }
     }
});

注意:城市下拉列表需要设置queryModel: 'remote',否则有缓存问题,即城市下拉列表加载数据时采用filterBy来过滤时首次加载有缓存。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11984612/viewspace-1271167/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/11984612/viewspace-1271167/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值