combotree.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Ext.ux.ComboTree = function(options){
var tree_div = "tree_"+(new Date()).getTime();
var cmbthis=this;
if(!options.maxHeight){
options.maxHeight = 200;
};
this.setTreeval=function(val){
this.treeval = val;
};
var wstr = '';
if(options.width) {
wstr = ';width:' + (options.width-5) + ';overflow:auto';
}
// 以下固定
options.editable=false;
options.mode='local';
options.triggerAction='all';
options.store=[[]];
options.tpl='<tpl for="."><div style="height:'+options.maxHeight+'px'+wstr+'"><div id="'+tree_div+'"></div></div></tpl>';
options.selectedClass='';
options.onSelect=Ext.emptyFn;
options.listeners={
'expand':function(){
this.tree.render(tree_div);
if (!this.tree.rendered) {
this.tree.render(tree_div);
}
this.el.focus();
Ext.ux.ComboTree.superclass.expand.apply(this, arguments);
}
};
options.tree=new Ext.tree.TreePanel({
loader: options.loader,
border:false,
root: options.root,
rootVisible: options.rootVisible,
useArrows: options.useArrows,
lines: options.lines,
listeners:{
'click':function(node){
cmbthis.setValue(node.text);
cmbthis.setTreeval(node.id);
cmbthis.collapse();
}
}
});
if(options.treeparams) {
options.tree.on('beforeload', function(node){
node.getOwnerTree().loader.baseParams = options.treeparams;
});
}
Ext.ux.ComboTree.superclass.constructor.call(this, options);
};
Ext.extend(Ext.ux.ComboTree, Ext.form.ComboBox, {
getValue:function(){
if(Ext.isDefined(this.treeval)) return this.treeval;
/*var node = this.tree.getSelectionModel().getSelectedNode();
if(node==null) {
return '';
}else{
return node.id;
}*/
}
});
Ext.reg('treecombo',Ext.ux.ComboTree);