Get string from symbol

Former Member
Former Member
Hi

Is it possible to get the string out of symbol?

I have a menu item like

<menu-item id="strength">@Strings.menu_label_strength</menu-item>

and would get the string from the id field out of it?

In the menu delegate I tried to output Sys.println(item.toString()) but that outputs only the word "Symbol" ...

best
Chris
  • No, it is not. If you really want this, you can use a Dictionary to map from the symbol to the string...

    const symbol_table = {
    :strength => ":strength",
    :length => ":length"
    // ...
    };


    Then you could print it out with...

    Sys.println(symbol_table[item]);


    Unfortunately, this does mean that you'd need to keep this code in sync with the definition of each of your symbols, which is a maintenance burden. If you're just using it for debugging though, it should work just fine.

    Travis
  • Former Member
    Former Member over 8 years ago
    Hi

    Thanks for the clarification. What a pitty. That means to have a lot of ifs to check for all the symbols.

    best
    Chris
  • Thanks for the clarification. What a pitty. That means to have a lot of ifs to check for all the symbols.

    Why would you do that? Just use a Dictionary as I showed above.