简体   繁体   中英

How to get all children of a node in fancytree?

I am trying to set a node's icon in fancytree. I found in online examples that I can use renderNode to do so:

 $("#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. 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.

if you need to calculate icons you can use the icon option :

$(...).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());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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