How can we improve Breeze.js?

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

124 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Thierry shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

6 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Anonymous commented  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    Yeah, pls, at least show us an example of how to bind the enums to a knockout select dropdown

  • Murray commented  ·   ·  Flag as inappropriate

    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

  • Laurentiu Macovei commented  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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?

Feedback and Knowledge Base