I know how to do this for one particular child node, but my problem is that I need to be able to iterate through the fancyTree and (using selectMode: 3) deem whether a node should be checked or not based on whether any of it's child Nodes have children.
I know this sounds confusing so an example would be a top level node called 'TopNode' with 2 children 'T2Node1' && 'T2Node2'. I want the node to stay selected if either of the two children have children of their own, otherwise set the node and its parent to unselectable.
My fancyTree code:
$("#surveyTargetTree").fancytree({
activeVisible: true,
checkbox: true,
extensions: ["filter", "glyph", "clones"],
glyph: {
map: {
doc: "fa fa-user",
folder: "fa fa-folder",
folderOpen: "fa fa-folder-open text-primary",
loading: "fa fa-spinner fa-pulse"
}
},
selectMode: 3,
filter: {
mode: "hide",
autoApply: true
},
source: collectiveJson...,
click: function (e, data) {
var treeDisabled = $("#surveyTargetTree").hasClass("ui-fancytree-disabled");
if (treeDisabled == false) {
var nodeType = data.node.refKey.split('_')[0];
var nodeParentType = data.node.parent.key.split('_')[0];
var emptyCount = 0;
if (nodeType == "adGroup" && nodeParentType == "OU" && data.targetType == "title") {
ViewGroupUsers(data.node.refKey);
}
if (data.targetType == "checkbox" && (nodeType != "aduser" && nodeType != "emailuser")) {
if (data.node.children == null) {
data.node.unselectable = true;
ErrorNotification('ErrorNotification');
data.node.render();
return false;
}
else
{
ProcessChildren(data.node);
}}
}
data.node.render();
}
and the recursive function..
function ProcessChildren(node)
{
var blah = 0;
var selectedNodes = [];
if (node.children != null) {
for (var i = 0; i < node.children.length; i++) {
var nodeType = node.children[i].refKey.split('_')[0];
if (node.children[i].children == null && (nodeType != "aduser" && nodeType != "emailuser")) {
node.children[i].unselectable = true;
blah++;
}
else
{
ProcessChildren(node.children[i])
}
}
}
}
If someone can point me in the right direction i'd appreciate it.
via bjjrolls
No comments:
Post a Comment