解决 Ext3.x 中 ComboboxTree 展开树时panel被关闭的bug

解决办法, 把ComboboxTree.js代码换成下面的:

Ext.form.ComboBoxTree = Ext.extend(Ext.form.ComboBox, {
        store: new Ext.data.SimpleStore({ fields: [], data: [[]] }),
        editable: false,
        shadow: false,
        mode: 'local',
        triggerAction: 'all',
        selectedClass: '',
        onSelect: null,
        canCollapse: true,
        constructor: function(_cfg) {
            if (_cfg == null) {
                _cfg = {};
            }
            Ext.apply(this, _cfg);
            this.treerenderid = Ext.id();
            this.tpl = String.format('<tpl for="."><div style="height:200px"><div id="ext-combobox-tree{0}"></div></div></tpl>', this.treerenderid);
            Ext.form.ComboBoxTree.superclass.constructor.apply(this, arguments);
            if (this.tree) {
                var cmb = this;
                this.tree.on('click', function(node) {
                    cmb.canCollapse = true;
                    if (Ext.isFunction(cmb.onSelect)) {
                        cmb.onSelect(cmb, node);
                    } else {
                        cmb.setValue(node.text);
                        if (cmb.hiddenField) {
                            cmb.hiddenField.value = node.id;
                        }
                    }
                    cmb.collapse();
                });
                //以下事件,让combobox能正常关闭
                this.tree.on('expandnode', function() { cmb.canCollapse = true; });
                this.tree.on('beforeload', function() { cmb.canCollapse = false; });
                this.tree.on('beforeexpandnode', function() { cmb.canCollapse = false; });
                this.tree.on('beforecollapsenode', function() { cmb.canCollapse = false; });
            }
            this.on('expand', this.expandHandler, this);
            this.on('collapse', this.collapseHandler, this);
        },
        expandHandler: function expand() {
            this.canCollapse = true;
            if (this.tree) {
                this.tree.render('ext-combobox-tree' + this.treerenderid);
                this.canCollapse = true;          
                this.tree.getRootNode().expand();
                
            }
        },
        collapseHandler: function collapse() {
            if (!this.canCollapse) {
                this.expand();
            }
        }
    
    });
    Ext.reg('combotree', Ext.form.ComboBoxTree);


调用代码:
new Ext.form.ComboBoxTree({
           id: 'mytree',
           hiddenName:'dept_no',
           fieldLabel:'机构',
            tree: new Ext.tree.TreePanel({
                root: new Ext.tree.AsyncTreeNode({ text: '--选择--', id: '0' }),
                rootVisible: false,
                border: false,
                dataUrl: '/AreaList.aspx',
                listeners: {
                    beforeload: function(n) { if (n) { this.getLoader().baseParams.id = n.attributes.id; } }
                }
            })/*,
            onSelect: function(cmb, node) {
                alert(node.attributes.text);
            }*/
        })

转载于:https://www.cnblogs.com/hapcn/archive/2011/07/13/2105268.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值