Last active
August 29, 2015 14:14
-
-
Save omarismail/032871359191198f35ac to your computer and use it in GitHub Desktop.
Traversing down a notebook tree
This file contains 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
getTreeData: function() { | |
var rootNotebooks = this.get('rootNodes'); | |
var data = []; | |
rootNotebooks.forEach(function(notebook) { | |
var currentNotebook = notebook; | |
var dataObj = Ember.Object.create({ | |
'text': currentNotebook.get('title'), | |
'state' : {'opened' : false, 'selected' : false }, | |
'children': [] | |
}); | |
dataObj['children'].pushObjects( | |
getChildren(currentNotebook, dataObj) | |
); | |
data.pushObject(dataObj); | |
}); | |
function getChildren (currentNotebook, dataObj) { | |
if (currentNotebook.get('hasChildren') === true) { | |
var subNotebooks = currentNotebook.get('subNotebooks'); | |
var arr = []; | |
subNotebooks.forEach(function(notebook) { | |
var newDataObj = Ember.Object.create({ | |
'text': notebook.get('title'), | |
'state' : {'opened' : false, 'selected' : false }, | |
'children': [] | |
}); | |
newDataObj['children'].pushObjects(getChildren(notebook, dataObj)); | |
arr.pushObject(newDataObj); | |
}); | |
return arr; | |
} else { | |
return []; | |
} | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment