Created
October 19, 2016 06:34
-
-
Save niisar/b82674294feffd2e4cf52db80b70dcce to your computer and use it in GitHub Desktop.
add level
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
vm.recursiveSearch = function find(source, id, currentLevel) { | |
for (var key in source) { | |
if (source.hasOwnProperty(key)) { | |
source[key].level = currentLevel; | |
var item = source[key]; | |
vm.kk.push(item); | |
if (item.nodeId === id) { | |
return item; | |
} | |
if (item.childNode) { | |
var subresult = vm.recursiveSearch(item.childNode, id, currentLevel + 1); | |
if (subresult) { | |
return subresult; | |
} | |
} | |
} | |
} | |
return null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.codeproject.com/Questions/1074776/Finding-level-of-any-node-parameter-object-in-give