Skip to content

Instantly share code, notes, and snippets.

@jgdovin
Created April 26, 2015 19:44
Show Gist options
  • Save jgdovin/e4866ee79a9b539e4940 to your computer and use it in GitHub Desktop.
Save jgdovin/e4866ee79a9b539e4940 to your computer and use it in GitHub Desktop.
nestCategories = function(parentId, dashes) {
if (parentId === undefined)
parentId = '';
if (dashes === undefined)
dashes = '';
var list = [];
var categories = Categories.find({parentId: parentId});
categories.map(function(category) {
list.push({
label: dashes + ' ' + category.name,
value: category._id
});
nestCategories(category._id, dashes + '-').map(function(item) {
list.push(item);
});
});
return list;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment