extjs4.1:两个combobox的联动

    一个combobox读取县地址码,change时间发生后,第二个combobox列出该县所属乡地址码。

    第一个combobox的onComboboxChange事件中,处理县地址码,生成新的URL,更新乡store。

注意取得reference的不同之处:

1、取得乡镇下拉列表框的reference

var comboboxXiang = Ext.getCmp('comboboxXiang');

2、取得乡store的reference

var StoreXiang = Ext.data.StoreManager.lookup('StoreXiang');

 

StoreXiang.js

 

Ext.define('MyApp.store.StoreXiang', {
    extend: 'Ext.data.Store',

    requires: [
        'MyApp.model.ModelXiang'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            storeId: 'StoreXiang',
            model: 'MyApp.model.ModelXiang',
            proxy: {
                type: 'ajax',
                url: '/cgi-bin/wind.exe/read_xiang?xiandm=360102',
                reader: {
                    type: 'json',
                    root: 'rows'
                }
            }
        }, cfg)]);
    }
});


 

 

 

MyViewport.js

  

Ext.define('MyApp.view.MyViewport', {
			extend : 'Ext.container.Viewport',

			layout : {
				type : 'border'
			},

			initComponent : function() {
				var me = this;

				Ext.applyIf(me, {
							items : [{
										xtype : 'panel',
										region : 'west',
										width : 271,
										title : 'My Panel',
										items : [{
													xtype : 'combobox',
													autoRender : true,
													autoShow : true,
													fieldLabel : '县区',
													blankText : '请选择市',
													emptyText : '请选择...',
													displayField : 'MC',
													store : 'StoreXian',
													valueField : 'DM',
													listeners : {
														change : {
															fn : me.onComboboxChange,
															scope : me
														}
													}
												}, {
													xtype : 'combobox',
													id : 'comboboxXiang',
													autoRender : true,
													store : 'StoreXiang',
													displayField : 'MC',
													valueField : 'DM',
													fieldLabel : '乡镇',
													blankText : '请选择市',
													emptyText : '请选择...'													
												}]
									}]
						});

				me.callParent(arguments);
			},
			onComboboxChange : function(field, newValue, oldValue, options) {
				var s = newValue.toString();
				//取得地址码前六位:县代码
				s = s.substr(0, 6);
				
				//取得乡镇下拉列表框的reference
				var comboboxXiang = Ext.getCmp('comboboxXiang');
				
				//取得乡store的reference
				var StoreXiang = Ext.data.StoreManager.lookup('StoreXiang'); 
				
				StoreXiang.proxy.url = '/cgi-bin/wind.exe/read_xiang?xiandm=' + s;
				StoreXiang.load();
				//重置乡镇下拉列表框
				comboboxXiang.clearValue();
			}

		});




转载于:https://www.cnblogs.com/cuibq/archive/2013/01/06/3801879.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值