Created
June 18, 2013 00:15
-
-
Save Jorgelig/5801671 to your computer and use it in GitHub Desktop.
Get option group from arraylist
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
function getOptionGroup = function(jsonList){ | |
var group; | |
var groups = {}; | |
var indexGroup = 0; | |
var optionsGroup = []; | |
$.each(jsonList, function(index, item){ | |
group = jsonList[index].group; | |
if(!(group in groups)) | |
groups[group] = []; | |
var option = {id: jsonList[index].id, name: jsonList[index].name}; | |
groups[group].push(option); | |
}); | |
$.each(groups, function(groupName, item){ | |
optionsGroup.push({groupName: groupName, options: item}); | |
indexGroup++; | |
}); | |
return optionsGroup; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment