欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

extjs关于treePanel+chekBox全部选中以及清空选中问题探讨

程序员文章站 2022-03-07 16:58:31
复制代码 代码如下: //树 var treepanel = new ext.tree.treepanel({ id:'ptree', region:'west', lay...
复制代码 代码如下:

//树
var treepanel = new ext.tree.treepanel({
id:'ptree',
region:'west',
layout:'anchor',
border:false,
rootvisible: false,
root:{},
listeners:{
render: function() {
authoritytree(treepanel); /*渲染树*/
},
checkchange: function(node, state) {
if (node.parentnode != null) {
//选中子节点让相应的父节点选中
var pnode = node.parentnode;
if (state || treepanel.getchecked(id, pnode) == "") {
pnode.ui.togglecheck(state);// 触发父节点被选中
pnode.attributes.checked = state;
}
}
treeid = node.attributes.id;
treename = node.attributes.text;
}
}
});
//操作按钮
tbar: [{
id: 'btnqingkong',
text: '清空',
iconcls: 'winupdate-icon',
handler: function() {
var nodes = ext.getcmp('ptree').getchecked();
if (nodes && nodes.length) {
for (var i = 0; i < nodes.length; i++) {
//设置ui状态为未选中状态
nodes[i].getui().togglecheck(false);
//设置节点属性为未选中状态
nodes[i].attributes.checked = false;
}
}
}
},{
id: 'btnquanxuan',
text: '全选',
iconcls: 'winupdate-icon',
handler: function() {
var nodet = ext.getcmp('ptree').getrootnode();
treechecktrue(nodet);
}
}]
/**
*checktree全选
*/
var treechecktrue = function(node)
{
node.eachchild(function (child) {
child.getui().togglecheck(true);
child.attributes.checked = true;
treechecktrue(child);
});
}
/**
*checktree清空
*/
var treecheckfalse = function(tree)
{
var nodes = tree.getchecked();
if(nodes && nodes.length){
for(var i=0;i<nodes.length;i++){
//设置ui状态为未选中状态
nodes[i].getui().togglecheck(false);
//设置节点属性为未选中状态
nodes[i].attributes.checked=false;
}
}
}