I\'m having trouble using the Select2 with various groups, only the latter appears.
I used like this. Working Fine.
$(document).on("ready", function() {
function formatResult(node) {
var level = 0;
if(node.element !== undefined){
level = (node.element.className);
if(level.trim() !== ''){
level = (parseInt(level.match(/\d+/)[0]));
}
}
var $result = $('' + node.text + '');
return $result;
};
$("#select2").select2({
placeholder: 'Select an option',
width: "300px",
templateResult: formatResult,
});
});