扩展combo下拉树

Ext.TreeComboflh = Ext.extend(Ext.form.ComboBox, {
  initList : function() {
   this.list = new Ext.tree.TreePanel({
    autoScroll : true,
    resizable : true,
    rootVisible : false,
    root : new Ext.tree.AsyncTreeNode({
       id : '',
       text : '根节点'
      }),
    loader : new Ext.tree.TreeLoader({
     dataUrl : this.dataUrl
         }),
    floating : true,
    height : 300,
    width : 80,
    listeners : {
     click : this.onNodeClick,
     scope : this
    },
    alignTo : function(el, pos) {
     this.setPagePosition(this.el.getAlignToXY(el, pos));
    }
   });
  },
  expand : function() {
   if (!this.list.rendered) {
    this.list.render(document.body);
    this.list.setWidth(this.el.getWidth());
    this.innerList = this.list.body;
    this.list.hide();
   }
   this.el.focus();
   Ext.TreeComboflh.superclass.expand.apply(this, arguments);
  },
  doQuery : function(q, forceAll) {
   this.expand();
  },
  collapseIf : function(e) {
   if (!e.within(this.wrap) && !e.within(this.list.el)) {
    this.collapse();
   }
  },
  onNodeClick : function(node, e) {
   if (node.attributes.description != null
     && node.attributes.description != '') {
    this.setValue(node.attributes.description);
    this.setRawValue(node.attributes.text);
   } else {
    this.setValue(node.id);
    this.setRawValue(node.attributes.text);
   }
   this.collapse();
  }
 });
 Ext.reg('treecomboflh', Ext.TreeComboflh);

你可能感兴趣的:(ext)