Created
June 23, 2017 12:05
-
-
Save cmcculloh-kr/5f4673e513c3bcdcab3da989e1318fba to your computer and use it in GitHub Desktop.
static data consuming tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findChildData = function findChildData (targetParent, rootData) { | |
if (_.isEmpty(targetParent)) { | |
return rootData; | |
} | |
if (rootData === undefined) { | |
return false; | |
} | |
for (var i = 0; i < rootData.length; i++) { | |
var potentialMatch = rootData[i]; | |
if (potentialMatch.attr && targetParent.attr && potentialMatch.attr.id === targetParent.attr.id) { | |
return potentialMatch.children; | |
} else if (potentialMatch.children) { | |
var foundChild = findChildData(targetParent, potentialMatch.children); | |
if (foundChild) { | |
return foundChild; | |
} | |
} | |
} | |
return false; | |
}; | |
var staticDataSourceConsumer = function staticDataSourceConsumer (openedParentData, callback) { | |
var childData = findChildData(openedParentData, staticData); | |
callback({ | |
data: childData | |
}); | |
}; | |
$('#myTree').tree({ | |
dataSource: staticDataSourceConsumer | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So much indentations! 😲