Last active
August 29, 2015 14:16
-
-
Save natsu90/40760237b3d91fdc7c50 to your computer and use it in GitHub Desktop.
recursive func for dropdown (js)
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 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