简体   繁体   English

如何在fancytree中获取节点的所有子节点?

[英]How to get all children of a node in fancytree?

I am trying to set a node's icon in fancytree. 我正在尝试在fancytree中设置节点的图标。 I found in online examples that I can use renderNode to do so: 我在在线示例中发现可以使用renderNode这样做:

 $("#tree").fancytree({
  // Image folder used for data.icon attribute.
  imagePath: "skin-custom/",
  // icon: false,
  renderNode: function(event, data) {
    // Optionally tweak data.node.span
    var node = data.node;
    // Some logic here
  }
});

I would like to go through the children of that node and if they are all selected, set an specific Icon. 我想浏览该节点的子级,如果全部选中,则设置一个特定的Icon。 But when I get the children, I only get the first level children, meaning I don't get the node's children's children. 但是当我得到孩子时,我只会得到一级孩子,这意味着我没有得到节点孩子的孩子。 Is there any way to achieve that? 有什么办法可以实现? Thanks in advance 提前致谢

The renderNode callback is only called on demand, eg for new nodes, when a status changes, or when node.renderStatus() is called. 仅在状态更改或调用node.renderStatus()时,才按需调用renderNode回调,例如对于新节点。

if you need to calculate icons you can use the icon option : 如果您需要计算图标,可以使用icon选项

$(...).fancytree({
    icon: function(event, data) {
        return data.node.isSelected() ? "a" : "b";
    },
    ...
});

You can use this pattern to iterate over all nodes: 您可以使用此模式遍历所有节点:

node.visit(function(n){
    console.log(n.isSelected());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM