ComboBox联动 (AJAX BS实现)

  //从webservice中取数据ajax
            Ext.Ajax.request({
                url: 'WebService.asmx/GetComboxFirst',
                method: 'POST',
                //jsonData: { UserName: "" },
                headers: { 'Content-Type': 'application/json;utf-8' },
                success: General,
                failure: On_Error
            });

            function General(result) {
                var data = Ext.util.JSON.decode(result.responseText);
                var ds = new Ext.data.Store({
                    proxy: new Ext.data.MemoryProxy(data.d),
                    reader: new Ext.data.JsonReader({ fields: [{ name: 'strText', type: 'string' }, { name: 'strValue', type: 'string'}] })
                });

                ds.load();
                var combox1 = new Ext.form.ComboBox({
                    store: ds,
                    displayField: 'strText',
                    valueField: 'strValue',
                    typeAhead: true,
                    mode: 'local',
                    forceSelection: true,
                    triggerAction: 'all',
                    emptyText: 'Select a state...',
                    selectOnFocus: true,
                    applyTo: 'combox1'
                });
                Genercombox2("1", 5);
                combox1.on('select', function (comboBox) {
                    //alert(comboBox.getRawValue() + '-' + comboBox.getValue());
                    Genercombox2("2", comboBox.getValue());
                });
            };

            function On_Error() {
            };
            //从webservice中取数据ajax

//从webserivce中取通过HttpProxy,因为asp.net数据是放在.d里面的,所以需要重写JsonReader来取数据.

  bJsonReader = Ext.extend(Ext.data.JsonReader, {
                read: function (response) {
                    var json = response.responseText;
                    //alert(json);
                    var o = Ext.decode(json);
                    //alert(o.d);
                    this.responseText = json;
                    if (!o) {
                        throw { message: 'JsonReader.read: Json object not found' };
                    }
                    return this.readRecords(o.d);
                }
            });
            var dshttpProxy = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: "WebService.asmx/GetComboxFirstByParam", method: 'POST', jsonData: { strParam: 10 }
                }),
                reader: new bJsonReader({
                    fields: [{ name: 'strText', type: 'string' }, { name: 'strValue', type: 'string'}]
                })
            });

            function Genercombox2(strtype, indexvalue) {

                if (strtype == "1") {
                    var combox2 = new Ext.form.ComboBox({
                        store: dshttpProxy,
                        displayField: 'strText',
                        autoLoad: false,
                        valueField: 'strValue',
                        typeAhead: true,
                        mode: 'local',
                        id: 'gameAreaID',
                        forceSelection: true,
                        triggerAction: 'all',
                        emptyText: 'Select a state...',
                        loadingText: 'Please Select',
                        anchor: '100%',
                        selectOnFocus: true,
                        applyTo: 'combox2'
                    });
                }
                if (strtype == "2") {
                    var parent = Ext.getCmp('gameAreaID');
                    parent.reset();
                    //重新获取数据
                    dshttpProxy.proxy = new Ext.data.HttpProxy({
                        url: "WebService.asmx/GetComboxFirstByParam", method: 'POST', jsonData: { strParam: indexvalue }
                    });
                    dshttpProxy.load();
                }
            }
            //从webserivce中取通过HttpProxy

转载于:https://www.cnblogs.com/meimao5211/p/3429615.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值