Enum in javascript and binding it to Dropdown list

It’s pretty clean to set, bind and use enum in your javascript

//Enum declaration
var AvailableActions = { “Action”: 1, “Priority”: 2, “Status”: 3 };

function Load()
for (var action in AvailableActions) {
jQuery(“#MandatoryActionList”).append(“<option value=” + AvailableActions[action] + “>” + action + “</option>”);

//Use the enum
AvailableActions[“Priority”] will return 2
action will return the string representation in this case e.g “Action”, “Priority”, or “Status”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s