extjs tree下拉列表_EXTJS下拉树ComboBoxTree参数提交及回显方法

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('');

this.store = new Ext.data.SimpleStore({fields:[],data:[[]]});

this.selectedClass = '';

this.mode = 'local';

this.triggerAction = 'all';

this.onSelect = Ext.emptyFn;

this.editable = false;

this.selectNodeModel = arguments[0].selectNodeModel || 'exceptRoot';

Ext.ux.ComboBoxTree.superclass.constructor.apply(this, arguments);

}

Ext.extend(Ext.ux.ComboBoxTree,Ext.form.ComboBox, {

expand : function(){

Ext.ux.ComboBoxTree.superclass.expand.call(this);

if(!this.tree.rendered){

this.tree.height = this.maxHeight;

this.tree.border=false;

this.tree.autoScroll=true;

if(this.tree.xtype){

this.tree = Ext.ComponentMgr.create(this.tree, this.tree.xtype);

}

this.tree.render(this.treeId);

var combox = this;

this.tree.on('click',function(node){

var isRoot = (node == combox.tree.getRootNode());

var selModel = combox.selectNodeModel;

var isLeaf = node.isLeaf();

if(isRoot && selModel != 'all'){

return;

}else if(selModel=='folder' && isLeaf){

return;

}else if(selModel=='leaf' && !isLeaf){

return;

}

combox.setValue(node);

combox.collapse();

});

var root = this.tree.getRootNode();

if(!root.isLoaded())

root.reload();

}

},

setValue : function(node){

var text = node.text;

this.lastSelectionText = text;

if(this.hiddenField){

this.hiddenField.value = node.id;

}

Ext.form.ComboBox.superclass.setValue.call(this, text);

this.value = node.id;

},

collapse:function(){

Ext.ux.ComboBoxTree.superclass.collapse.call(this);

document.getElementById("myhiddencomboboxtree").value = this.getRawValue();

},

getValue : function(){

return typeof this.value != 'undefined' ? this.value : '';

}

});

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

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

添加该隐藏字段代码:

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

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

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值