jean-emmanuel / open-stage-control

Libre and modular OSC / MIDI controller
https://openstagecontrol.ammd.net
GNU General Public License v3.0
702 stars 88 forks source link

Advanced syntax : key instead of label for value #625

Closed paulmacmillan closed 4 years ago

paulmacmillan commented 4 years ago

Hi Jean-Emmanuel, first of all thank you for the amazing work you're doing on this project ! Truly mind blowing.

Here is the situation :

if we have a switch component with a values field like :

{
    "homer": simpson,
    "rick": morty
}

Is there a way, when using the advanced syntax (@{id.value}) to set the label field of another component, to use the key (or label as described in the documentation) (here it would be homer) instead of the value (simpson).

Been reading the doc for hours now and cannot find the way to do it.

Thanks for your help

jean-emmanuel commented 4 years ago

In case this was closed by accident, here is a snippet:

JS{{
var object = @{switch_1.values},
    value = @{switch_1}
return Object.keys(object).find(key => object[key] === value)
}}

Source: https://stackoverflow.com/a/28191966

paulmacmillan commented 4 years ago

Thank you so much for your help ! So quick to answer as usual. In fact I found another solution you posted earlier on discourse and didn't want to bother you ^^ Btw, it's very kind of you to give the explanation for the solution though so we can better understand.