extjs - 选中和取消选中树面板中的节点

标签 extjs extjs4.2 treepanel

To do : Checking a child should check parents up the tree, and clearing a parent checkbox should clear all of it's children.


例子 :
parent 1
--child1
--child2
--subChild1
--subChild2

Scenario1 :In above case, if subChild1 is checked,then parent1 and child2 should also be checked.

Scenario2 :If parent1 is checked,then all its children(checked) should be unchecked.


从这里 Check/Uncheck Nodes ,只有当父节点被选中时,它的子节点才会被选中。
他们是按照我想要的方式实现的,但无法弄清楚(实现),因为复杂性级别足以让我理解。这是 reference
请帮我解决这个功能。谢谢。任何帮助将不胜感激。

最佳答案

这是我所做的。花了一些时间,但它奏效了。

checkchange : function(node, checked, opts) {

 function clearNodeSelection(node){
  //node is not leaf node
   console.log(node);
   leafNode = node.raw.leaf;
   if(!leafNode){
      node.cascadeBy(function(node) {
            node.set('checked', false);
       })
   }
 }

 if(!checked){
    console.log("inside !checked : "+checked);
    clearNodeSelection(node);
 }

 function selectParentNodes(node){
     var parentNode = node.parentNode;
     if(parentNode){
        parentNode.set('checked', true);
        selectParentNodes(parentNode);
    }
 }

 selectParentNodes(node);
}

Atlast,谢谢@VDP。 'SO' 太棒了。

关于extjs - 选中和取消选中树面板中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21331777/

相关文章:

extjs4.1 - 未捕获的类型错误 : Cannot read property 'internalId' of undefined( WHILE SORTING NODES ON EXPAND)

extjs - 在 Android 设备或模拟器上查看时,Sencha 触摸应用程序保持在蓝色加载屏幕上

javascript - 在 extjs 中为 DOM 操作分配 tpl 值

javascript - 无法为 Extjs 文本字段设置焦点

javascript - ExtJS 4 : Window not sizing correctly on first show

javascript - 如何在extjs中将网格面板添加到树形网格的最后一个节点

javascript - extjs 在 TreePanel 中加载图像

javascript - 使用 URL 中的 # 访问选项卡面板中的不同选项卡 - ExtJS

extjs - 为什么我的关键事件不起作用

ExtJS 4.2.1 - 无法从 Controller 获取 View 实例