extjs關于treePanel+chekBox全部選中以及清空選中問題探討

extjs關于treePanel+chekBox全部選中以及清空選中問題探討,treePanel+chekBox全部選中以及清空選中,想必大家在學習使用過程中都見過這種效果吧,接下來為大家詳細介紹下實現過程及細節,感興趣的朋友可以參考下哈
關鍵字:extjs、treePanel、chekBox
復制代碼 代碼如下:

//樹
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;
}
}
}
众人帮太赚钱了