jquery - Populate an array with Enum variable - javascript -


okay, have code populates array enum variable in javascript. however, looks extremely outdated , clunky.

i'm wondering if of jquery / javascript gurus have more elegant (best practice) method functionality.

current: (which works ugly)

var myenum = { first: 1, second: 2, third: 3};  if (object.freeze) object.freeze(rolesenum); 

creating array (again works ugly)

var aenumarray = [             myenum.first,             myenum.second,             myenum.third             ];         var aenums = new array();         $.each(aenumarray , function (i, x) {             aenums .push({                 id: x,                 name: converters.rolestostringconverter(x)             });         });     aenums.sort(function (x, y) { return (x.name == y.name) ? 0 : (x.name > y.name ? 1 : -1); }); 

finally, after of that, used populate

combobox.clearitems(); combobox.additems(aenums); 

sure lot of work populate combo box.

it hard tell trying accomplish, can tell think might help.

http://jsfiddle.net/hbvju/

var myenum = {   first: 1,   second: 2,   third: 3 }; var enumsobj = []; for(var prop in myenum){     enumsobj.push({id: myenum[prop], name: prop}) } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -