1

I have a flags enum property in my backend service (C#) and on the frontend (angular / js) a multi select list which uses an array as source.

If I recreated the enum in javascript, is it possible to take the integer value (from the service) and map it to the flag values? i.e. given the number 6 from my service, I could populate an array (or something) with the values [red, blue] which I could use to populate the multi select.

  var myEnum = {
  none: 0,
  green: 1,
  red: 2,
  blue: 4
}

I've found a few examples regarding enums in javascript but they don't seem to be exactly what I'm after.

Many thanks

Michael Harper
  • 1,531
  • 2
  • 25
  • 42

1 Answers1

0

I advice against Dart enums if you pass data in and out of Dart. Use "old style" enums instead as shown in this answer https://stackoverflow.com/a/13900635/217408 They are less fragile and flexible, a bit more verbose though.

I use IntelliJ live templates for better experience. There is also the built_enums package, but I haven't tried it yet myself.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567