Skip to content

Instantly share code, notes, and snippets.

@natsu90
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natsu90/40760237b3d91fdc7c50 to your computer and use it in GitHub Desktop.
Save natsu90/40760237b3d91fdc7c50 to your computer and use it in GitHub Desktop.
recursive func for dropdown (js)
var folders = <?=$json_encode($folders)?>,
indent = [],
get_menu = function(folders, folder_id){
var html = '';
if(typeof folder_id == 'undefined')
folder_id = 0;
folders.forEach( function(folder) {
if(folder.file_parent_id == folder_id) {
if(folder.file_parent_id > 0)
indent[folder.id] = indent[folder.file_parent_id]+1;
else
indent[folder.id] = 0;
html += '<option value="'+folder.id+'">';
for(var i = 0; i < indent[folder.id]; i++)
{
html += '---';
}
html += folder.file_display_name+'</option>';
html += get_menu(folders, folder.id);
}
});
return html;
};
$('select#menu').html(get_menu(folders));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment