日期:2014-05-16 浏览次数:20833 次
var comboxTree = new Ext.form.ComboBox({ store:new Ext.data.SimpleStore({fields:[],data:[[]]}), editable:false, mode: 'local', width:100, listWidth:220, triggerAction:'all', tpl: "<div style='height:300px'><div id='thistree'></div></div>", selectedClass:'', onSelect:Ext.emptyFn }); var tree = new Ext.tree.TreePanel({ root:new Ext.tree.AsyncTreeNode({text: '部门'}), width:220, border:false, autoScroll:true, autoHeight:true, rootVisible:false, loader: new Ext.tree.TreeLoader({dataUrl:'loadDepartTree?node=0201'}) }); tree.on('click',function(node){ comboxTree.setValue(node.id); comboxTree.setRawValue(node.text); v comboxTree.collapse(); }); comboxTree.on('expand',function(){ tree.render('thistree'); tree.expandAll(); comboxTree.ownerCt.doLayout(true); }); var form = new Ext.form.FormPanel({ region:'center', items:[ comboxTree ] }); var view= new Ext.Viewport({ //hidden:true, layout:'border', items:[ form ], renderTo:Ext.getBody() }); view.show();
Ext.ux.ComboBoxTree = Ext.extend(Ext.form.ComboBox, { tree: null, SelectAll: true, displayText: 'Text', constructor: function (config) { var $this = this; var rid = Math.floor(Math.random() * 1000); this.tree = new Ext.tree.TreePanel({ loader: config.loader, border: false, root: config.root, rootVisible: config.rootVisible, autoScroll: false, listeners: { click: function (node, e) { if ($this.SelectAll) { if ($this.displayText == 'Text') $this.setValue(node.attributes.name, node.attributes.id); else if ($this.displayText == 'Name') $this.setValue(node.getPath('name'), node.attributes.id); $this.collapse(); } else if (node.attributes.leaf) { if ($this.displayText == 'Text') $this.setValue(node.attributes.name, node.attributes.id); else if ($this.displayText == 'Name') $this.setValue(node.getPath('name'), node.attributes.id); $this.collapse(); } } } }); config = Ext.apply({ editable: false, triggerAction: 'all', autoScroll: false, typeAhead: true, tpl: "<div style='height:200px'><div id='_" + rid + "'></div></div>", listeners: { expand: function () { this.tree.render('_' + rid); //tree.expandAll(); } } }, config); Ext.ux.ComboBoxTree.superclass.constructor.call(this, config); } }) ///贴一段我的代码