Retrieve values of an enum server side to be able to use it client side

-
Anonymous commented
As a workaround in the meantime, you could create global "enums" from your metadata like this:
manager.fetchMetadata()
.then(function (data) {// extract all enums als global objects
ko.utils.arrayForEach(data.schema.enumType, function (c) {
window[c.name] = {};
ko.utils.arrayForEach(c.member, function (m) {
window[c.name][m.name] = m.value;
});
});});
So if you had an enum called "Status", you would now have a global object that you can call:
var currentStatus = Status.Done; //returns the value as defined in the server side enum
-
Fredrik commented
Yeah, pls, at least show us an example of how to bind the enums to a knockout select dropdown
-
Murray commented
Yes please expose these. As stated above you are passing these to the client but we can't access them in the breeze api. I would give this 10 votes if i had it
-
Mark van Proctor commented
The enumType and all its values / names are in the metadatastore... if only they were accessible :)
-
Laurentiu Macovei commented
This is so trivial, you're actually have it in the metadata.
Don't understand why they haven't epxosed it in the first place. -
Adam Pawsey commented
From what I can see this is just a matter of exposing the data in the api? looking at the metadata it includes the definitions for the enums. There just isn't a way to actually get that data out of the metadata store. Looking at the relevant property of my type, it's enumType property has the value Edm.Self.EnumType but it's just a string and no where else can you actually just get those values.
Correct me if I'm wrong?