SOLVED: Get(this) in a menu-widget

Hi there

I have following problem...

See the first entry in the menu/values:


with get(this) I can access to the value = 0
but how I can access value "C"?

Something like this ? Object.keys() - JavaScript | MDN

It does not work... thanks

I dont know, if I can use %key, but i think this is only for the label.

var val = value,
    pair = Object.entries(getProp(this, 'values')).find(entry=>entry[1] === value), // get [key, value] pair in values that matches current value
    key = pair !== undefined ? pair[0] : undefined // get key from matching pair if any

(you can use value instead of get(this) in onValue)

Oops... that's a complicated one.
I would never have thought of that.
Many thanks for that

In a more pedagogic manner:

var values = getProp(this, 'values'),
    val = value,
    key // not assigned -> implicit "= undefined"

// loop over keys in values
for (var k in values) {
  // if the value associated with that key matches current value
  if (values[k] === val) {
     // store the key and exit loop
     key = k
1 Like