Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can i get the index selected of a selection settings item?

ANSWERED

Hello,

I have a settings select item that looks like this:

 

<Select
        label={`1`}
        settingsKey="1"
        options={[
          {name:"Mathe"},
          {name:"Deutsch"},
          {name:"Französisch"},
          {name:"Physik"},
          {name:"Englisch"},
          {name:"Informatik"},
          {name:"Religion"},
          {name:"Musik"},
          {name:"Geschichte"},
          {name:"Kunst"},
          {name:"Chemie"},{name:"Biologie"},
          {name:"Geografie"},
          {name:"Sport"},
          {name:"-"}
  ]}
/>

 

 I want to save the index of the item that is selected in companion settings to a variable in companion/index.js

(Index of "Mathe" for example would be 0)

How can i do this, because a settingsStorage.getItem() on it returns

weird things like this:

 '{"values":[{"name":"Deutsch"}],"selected":[1]}', '{"values":[{"name":"Informatik"}],"selected":[5]}', '{"values":[{"name":"Französisch"}],"selected":[2]}', '{"values":[{"name":"Physik"}],"selected":[3]}', '{"values":[{"name":"Englisch"}],"selected":[4]}', '{"values":[{"name":"Informatik"}],"selected":[5]}'

 Thanks

Aaron

Phone: OnePlus Nord Android 11, Watch: Versa 3
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

That's just a stringified JSON object. Convert it back to a JS object using JSON.parse(), then access whatever fields you want.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
2 REPLIES 2

That's just a stringified JSON object. Convert it back to a JS object using JSON.parse(), then access whatever fields you want.

Peter McLennan
Gondwana Software
Best Answer

Thank you, i'll try it

Phone: OnePlus Nord Android 11, Watch: Versa 3
Best Answer
0 Votes