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
    评论
好的,我会尝试回答你的问题。以下是一个 ExtJS4.2 实例,包含一个表格和一个带有联动下拉列表的列: ```javascript Ext.require([ 'Ext.grid.*', 'Ext.data.*', 'Ext.form.*' ]); Ext.onReady(function() { // 创建一个简单的数据存储 var store = Ext.create('Ext.data.Store', { fields: ['name', 'email', 'phone', 'department'], data: [ { 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224", "department": "Sales" }, { 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234", "department": "Marketing" }, { 'name': 'Homer', "email":"homer@simpsons.com", "phone":"555-222-1244", "department": "Engineering" }, { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254", "department": "Support" } ] }); // 创建一个下拉框的存储 var departmentStore = Ext.create('Ext.data.Store', { fields: ['name'], data : [ { "name": "Sales" }, { "name": "Marketing" }, { "name": "Engineering" }, { "name": "Support" } ] }); // 创建一个表格 var grid = Ext.create('Ext.grid.Panel', { renderTo: Ext.getBody(), store: store, height: 250, width: 500, title: 'Employee Directory', columns: [ { header: 'Name', dataIndex: 'name' }, { header: 'Email', dataIndex: 'email', flex: 1 }, { header: 'Phone', dataIndex: 'phone' }, // 创建一个带有联动下拉列表的列 { header: 'Department', dataIndex: 'department', editor: { xtype: 'combobox', store: departmentStore, displayField: 'name', valueField: 'name', editable: false, forceSelection: true } } ], // 启用编辑功能 plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }) ] }); }); ``` 这个例子中,我们创建了一个名为 `grid` 的表格,包含四个列:姓名、电子邮件、电话和部门。其中,部门列是一个带有联动下拉列表的列,该下拉列表的数据存储在 `departmentStore` 中。我们使用 `Ext.grid.plugin.CellEditing` 插件启用了编辑功能,从而允许用户编辑表格中的数据。 希望这个例子对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值