http://blog.csdn.net/wjlht/article/details/6085245

使用extjs可以构造出下拉数,但是不方便向form提交参数,在此,笔者想到一个办法,很方便ComboBoxTree向form提交。

原理:

在form中增加一个隐藏的字段,当在comboBoxTree中选定值后自动在隐藏字段中赋值。

为实现此方法,需要重载comboBoxTree中collapse事件方法。

Ext.ux.ComboBoxTree = function(){
    this.treeId = Ext.id()+'-tree';
    this.maxHeight = arguments[0].maxHeight || arguments[0].height || this.maxHeight;
    this.tpl = new Ext.Template('<tpl for="."><div style="height:'+this.maxHeight+'px"><div ).value = this.getRawValue();
    }, 
    
    getValue : function(){
        return typeof this.value != 'undefined' ? this.value : '';
    }
});

Ext.reg('combotree', Ext.ux.ComboBoxTree);

 

红色部分就是增加的重载代码,作用是当下拉数收起后,将id为myhiddencomboboxtree的隐藏字段赋值,在form中添加该隐藏字段就可以提交参数了。

添加该隐藏字段代码:

<input type="hidden"  name="aaa"  value='hello'/>

 

 

 

至于向comboBoxTree赋值,则在javascript中直接调用函数comboBoxTree.setValue(),例如:

comboBoxTree.setValue({id:'0',text:'新闻类型'})

 

 

至此,comboxTree的传值和回显就全部解决了,大家就可以在项目中使用comboBoxTree来显示下拉树了。对于在需要将类型或单位无限级划分的地方比较适用。

相关文章:

  • 2021-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2021-10-17
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案