extjs4.1下改combobox为treecombo 并带有check

1、功能描述:

最近用户要求在combobox选择填入时,能够在树结构中选择节点,并保存和修改。

2、代码展示:

Ext.define("HgTreeCheckCombo", {
extend : "Ext.form.field.ComboBox",
alias : 'widget.hgtreecheckcombo',
requires : [],
multiSelect : true,
autoScroll : true,
checkModel : '',
treeplanname : '',
pid : '',
comdisplayField : '',
comvalueField : '',
initComponent : function() {
var cfg = this.cfg || {};
var isrootVisible = cfg.isrootVisible || false;
Ext.apply(this, {
editable : false,
queryMode : 'local',
displayField : this.comdisplayField,
valueField : this.comvalueField,
select : Ext.emptyFn
});
this.displayField = this.displayField || 'text', this.treeid = Ext.String
.format('tree-combobox-{0}', Ext.id());


this.tpl = Ext.String.format('<div id="{0}"></div>', this.treeid);
var me = this, checkrecode = [];
this.tree = Ext.create(this.treeplanname, {
pid : me.pid,
height : 300,
autoScroll : true
});
this.tree.on('checkchange', function(node, check) {
var tree = this;
var checkModel = me.checkModel;
if (check) {
checkrecode.push(node);
}else{
checkrecode.pop(node);
}
if (checkModel == 'single') {
me.setValue(node);
me.collapse();
} else if (checkModel == 'multiple') {
if (me.multiSelect) {
me.setValue(checkrecode);
}
}
});


me.on('expand', function() {
if (!this.tree.rendered) {
var treestore = this.tree.getStore(),node;

//在修改时,通过现在combo显示的真实值,在展开combo时,tree的相应节点要被选中
if(!Ext.isEmpty(me.getValue())){
value = Ext.Array.from(me.getValue());
for(i=0,len = value.length; i < len; i++){
node = treestore.getNodeById(value[i]);
if(node){
node.set("checked", true);
checkrecode.push(node);
}
}
}
this.tree.render(this.treeid);
}
});

//创建一个Ext.data.store,因为普通的store里有一个方法,这样在修改时可以找到你选择的记录内容,这个store的结果要和treestore的结果一样
this.store = Ext.create("BmzdStore", {
autoLoad : true,
proxy : {
extraParams : {
pid : me.pid
},
type : 'ajax',
api : {
read : './pa/bmzd!childlist.html'
},
reader : {
type : 'json',
root : 'bmzds',
successProperty : 'success'
}
}
});
// this.store = this.tree.getStore();
this.callParent(arguments);
},
constructor : function(config) {
HgTreeCheckCombo.superclass.constructor
.call(this, config);
}
});


有不足之处请指点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值