arvind
arvind

Reputation: 189

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

Upvotes: 0

Views: 2487

Answers (1)

mar10
mar10

Reputation: 14794

The renderNode callback is only called on demand, e.g. 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());
});

Upvotes: 1

Related Questions