//右侧菜单树 var centerPanel = Ext.create('Ext.tree.Panel', { …… listeners:{ checkchange:function (node,checked,eOpts){ //选中事件 setChildChecked(node,checked); setParentChecked(node,checked); } } });
function setChildChecked(node,checked){ node.expand(); node.set({checked:checked}); if(node.hasChildNodes()){ node.eachChild(function(child) { setChildChecked(child,checked); }); } } function setParentChecked(node,checked){ node.set({checked:checked}); var parentNode = node.parentNode; if(parentNode !=null){ var flag = false; parentNode.eachChild(function(child) { if(child.data.checked == true){ flag = true; } }); if(checked == false){ if(!flag){ setParentChecked(parentNode,checked); } }else{ if(flag){ setParentChecked(parentNode,checked); } } } }