Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enums with jQuery?

$("#bc [id$=_dropdownID]").change(function() {
    if (this.value == '2' || this.value == '3') {
        $("#bc .pnl").show();
    }
    else {
        $("#bc .pnl").hide();
    }

I have the following code in jQuery. Is there any way I can replace the hard coded constants 2 and 3 in the above code with a c# enum? Does jQuery support enums and if so how can this be achieved? Any suggestions welcome....

like image 632
chugh97 Avatar asked Sep 02 '10 09:09

chugh97


1 Answers

You would have to duplicate the enum in JavaScript like so:

var myEnum = {
         OneValue: 2,
         AnotherValue: 3
};

then you can use it like this:

this.value === myEnum.OneValue || this.value === myEnum.AnotherValue;
like image 69
sirrocco Avatar answered Oct 12 '22 15:10

sirrocco