带CheckBox的 Extjs ComboboxTree

2年多不来博客园了,呵呵,很想念

N多人想用这个,以前项目用到了,代码如下

 实现效果如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
  1Ext.onReady(function()
  2ExpandedBlockStart.gifContractedBlock.gif    {
  3        //自定义扩展一个带Tree的comboBox
  4ExpandedSubBlockStart.gifContractedSubBlock.gif        Ext.ux.LovTreeCombo = Ext.extend(Ext.form.ComboBox, {
  5ExpandedSubBlockStart.gifContractedSubBlock.gif        initList: function() {
  6ExpandedSubBlockStart.gifContractedSubBlock.gif            this.list = new Ext.tree.TreePanel({
  7                floating: true,
  8                autoHeight: false,
  9                autoExpand: true,
 10                height: 240,
 11                rootVisible: false,
 12                containerScroll: true,
 13                dataUrl: this.url,
 14ExpandedSubBlockStart.gifContractedSubBlock.gif                root: {
 15                    nodeType: 'async',
 16                    text: 'root',
 17                    draggable: false,
 18                    id: 'root'
 19                }

 20         ,
 21
 22ExpandedSubBlockStart.gifContractedSubBlock.gif                listeners: {
 23                    checkchange: this.onNodeCheckChange,
 24                    scope: this
 25
 26                }
,
 27                useArrows: true
 28ExpandedSubBlockStart.gifContractedSubBlock.gif                alignTo: function(el, pos) {
 29                    this.setPagePosition(this.el.getAlignToXY(el, pos));
 30                }

 31            }
);
 32
 33        }
,
 34
 35ExpandedSubBlockStart.gifContractedSubBlock.gif        expand: function() {
 36ExpandedSubBlockStart.gifContractedSubBlock.gif            if (!this.list.rendered) {
 37                this.list.render(document.body);
 38                this.list.setWidth("660px"); 
 39                this.innerList = this.list.body;
 40                this.list.hide();
 41            }

 42            this.el.focus();
 43            Ext.ux.LovTreeCombo.superclass.expand.apply(this, arguments);
 44        }
,
 45
 46ExpandedSubBlockStart.gifContractedSubBlock.gif        doQuery: function(q, forceAll) {
 47            this.expand();
 48        }
,
 49
 50ExpandedSubBlockStart.gifContractedSubBlock.gif        collapseIf: function(e) {
 51ExpandedSubBlockStart.gifContractedSubBlock.gif            if (!e.within(this.wrap) && !e.within(this.list.el)) {
 52                this.collapse();
 53            }

 54        }
,
 55
 56        valueList: [],
 57        textList: [],
 58
 59ExpandedSubBlockStart.gifContractedSubBlock.gif        getvalueList: function() {
 60            return this.valueList;
 61        }
,
 62
 63ExpandedSubBlockStart.gifContractedSubBlock.gif        onNodeCheckChange: function(node, e) {
 64ExpandedSubBlockStart.gifContractedSubBlock.gif            if (!node.leaf) {
 65ExpandedSubBlockStart.gifContractedSubBlock.gif                node.expand(truefalsefunction() {
 66ExpandedSubBlockStart.gifContractedSubBlock.gif                    node.eachChild(function(child) {
 67                        child.ui.toggleCheck(node.attributes.checked);
 68                        child.attributes.checked = node.attributes.checked;
 69                        child.fireEvent('checkchange', child, node.attributes.checked);
 70                    }
);
 71
 72                }
);
 73
 74            }

 75ExpandedSubBlockStart.gifContractedSubBlock.gif            else {
 76                //alert(1)
 77                var nodeValue = node.id;
 78                var test = this.valueList.indexOf(nodeValue);
 79
 80ExpandedSubBlockStart.gifContractedSubBlock.gif                if (test == -1 && node.attributes.checked) {
 81                    this.valueList.push(nodeValue)
 82                    this.textList.push(node.text);
 83                }

 84
 85ExpandedSubBlockStart.gifContractedSubBlock.gif                if (test != -1 && !node.attributes.checked) {
 86                    this.valueList.remove(nodeValue);
 87                    this.textList.remove(node.text);
 88                }

 89
 90                //if(window.console){console.log(this.valueList.toString())}共选择了'+this.valueList.length.toString()+'菜单:'+
 91                var str = this.textList.toString();
 92                this.setRawValue(str);
 93
 94
 95ExpandedSubBlockStart.gifContractedSubBlock.gif                if (this.hiddenField) {
 96                    this.hiddenField.value = node.id;
 97                }

 98            }

 99            //this.collapse();
100        }
,
101        url: '',
102ExpandedSubBlockStart.gifContractedSubBlock.gif        reset: function() {
103
104            this.valueList.length = 0;
105            this.textList.length=0;
106            this.applyEmptyText();
107
108        }
,
109
110
111ExpandedSubBlockStart.gifContractedSubBlock.gif        resetNode: function(node) {
112            this.collapseNode(node);
113            this.uncheckNode(node);
114        }
,
115
116ExpandedSubBlockStart.gifContractedSubBlock.gif        collapseNode: function(node) {
117ExpandedSubBlockStart.gifContractedSubBlock.gif            if (node.isExpanded()) {
118                node.collapse();
119            }

120        }
,
121
122ExpandedSubBlockStart.gifContractedSubBlock.gif        uncheckNode: function(node) {
123
124ExpandedSubBlockStart.gifContractedSubBlock.gif            if (node.getUI().isChecked()) {
125ExpandedSubBlockStart.gifContractedSubBlock.gif                if (window.console) { console.log("未能选中此节点ID " + node.attributes.id) }
126
127                node.getUI().toggleCheck(false);
128            }

129        }

130
131
132    }
);
133    
134    //这边注册一下子
135    Ext.reg('treecombo', Ext.ux.LovTreeCombo);
136
137   //这边是使用方法
138ExpandedSubBlockStart.gifContractedSubBlock.gif    var lovTreeCombo2 = new Ext.ux.LovTreeCombo({
139    id:'cmb',
140    renderTo: 'cmb',
141    url: 'LoadTreeMenu.aspx ',
142    emptyText: '选择类型',
143    width: 660,
144    listWidth: 180
145    }
);
146    
147    }
)

 

转载于:https://www.cnblogs.com/yzhxhwt/archive/2009/07/13/1522819.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值