ComboBoxTree

参考别人的改的


Ext.namespace("Ext.ux.form");
/**
* create by wjc
*/
Ext.ux.form.ComboBoxTree = Ext.extend(Ext.form.ComboBox, {
treeId : Ext.id()+'-tree',
maxHeight :300,
selectedClass : '',
mode : 'local',
triggerAction: 'all',
onSelect : Ext.emptyFn,
editable : false,

//all:所有结点都可选中
//exceptRoot:除根结点,其它结点都可选
//folder:只有目录(非叶子和非根结点)可选
//leaf:只有叶子结点可选
selectNodeModel : 'exceptRoot',
//private
initComponent: function(){
this.initComboBoxTree();
Ext.ux.form.ComboBoxTree.superclass.initComponent.call(this);
},
initComboBoxTree:function(){
this.tpl = new Ext.Template('<tpl for="."><div style="height:'+this.maxHeight+'px"><div id="'+this.treeId+'"></div></div></tpl>');
this.store = new Ext.data.SimpleStore({fields:[],data:[[]]});
if(!this.tree){
var initComboBoxTree_Page =this;
this.tree = new Ext.tree.TreePanel({
loader: new Ext.tree.DWRTreeLoader({
dataUrl:this.DWRfunc,
isteners : {
'beforeload' : function(node) {
initComboBoxTree_Page.getLoader().args[0]=(node.id!='0'?node.id:"1");
}
}
}),
root : new Ext.tree.AsyncTreeNode({
text: this.rootlable,
draggable:false,
id:'1'
})
});
}
},
expand : function(){
Ext.ux.form.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;
if(node.text)
text = node.text;
if(this.valueField){
var r = this.findRecord(this.valueField, node.text);
if(r){
text = r.data[this.displayField];
}else if(Ext.isDefined(this.valueNotFoundText)){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = node.text;
}
Ext.ux.form.ComboBoxTree.superclass.setValue.call(this, text);
this.value = node.text;
return this;
},

getValue : function(){
return typeof this.value != 'undefined' ? this.value : Ext.ux.form.ComboBoxTree.superclass.getValue.call(this);
}
});

Ext.reg('combotree', Ext.ux.form.ComboBoxTree);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值