Skip to content

Instantly share code, notes, and snippets.

@Jorgelig
Created June 18, 2013 00:15
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 Jorgelig/5801671 to your computer and use it in GitHub Desktop.
Save Jorgelig/5801671 to your computer and use it in GitHub Desktop.
Get option group from arraylist
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