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

Settings changed what it returns

ANSWERED

Hello,

 

I have recently had users complain that my clock faces are no longer working.  I was confused since I had been using the same face for a while now (since my last update).  So, I chased down the error to the way the Select function in Settings returns information.  There is a new "selected":... added on to the end which is the index of the value selected. 

 

app/index.js:104,7[1:39:51 PM]pre myTimeString <{"values":[{"name":"GMT","value":"+25"}],"selected":[5]}>

 

This caused issues in my code and appears to be an unintended consequence of an unannounced update.  The error does not appear unless you re-install the clock face.  What gives?

 

I write the "evt.data.newValue" as an ascii file so that I can use the info later.  Since I have yet to figure out how to use the information in another way (myVariable = evt.data.newValue[value] crashes when tried), changing the return info without a heads-up caused people who download my clocks grief.

 

 

Please, either publish when you change things (I am still waiting for you to include the time zone information in your Date function) or tell give me an example of how to access the data in an array fashion.

 

Thanks.

 

PS - Yes, I have already submitted updates to correct for this to Fitbit for publishing

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Perhaps

 

let data = JSON.parse(evt.data.newValue);
console.log(data.values[0].value);

View best answer in original post

Best Answer
4 REPLIES 4

Sorry this broke for you, it looks like the order of the elements changed.

 

It's actually a string of a JavaScript object, so you should JSON.parse, then access the properties of the object instead.

 

I hope that helps1

Best Answer
0 Votes

 

 

Thank you for the record response time!  I have tried to parse the info, but apparently lack the skills to access the info.  I think I am missing a layer somewhere, but cannot figure it out.  Do you see what I am missing?

 

 

The evt.data.newValue comes from the examples.  I have no issue getting/using evt.data.key.

 

When I  try:

      let myTemp = JSON.parse(evt.data.newValue)[0];
      console.log(`myTemp data parsed <${myTemp}>`);

I get:

 

myTemp data parsed <undefined>

 

 

As a reminder, the full return is:

{"values":[{"name":"Zulu - 4","value":"-04"}],"selected":[1]}

 

When I try:

let myTemp = JSON.parse(evt.data.newValue)[0];
console.log(`myTemp data parsed <${myTemp.value}>`);

 I get:

4:21:31 PM]Unhandled TypeError: Cannot read property 'value' of undefined
? at app/index.js:105,7

I have tried bracketing value and putting it in quotes.  I still get an error.  I tried parsing myTemp and that returns an error.

 

Can you throw me a hint or answer?

 

Thanks again.

 

Best Answer
0 Votes

Perhaps

 

let data = JSON.parse(evt.data.newValue);
console.log(data.values[0].value);
Best Answer

Wow...that works and simplifies my code.  Thanks!

Best Answer