05-24-2019 06:00
05-24-2019 06:00
I have a TileList with checkbox-tile's and using code similar to the code below to determine if a box is selected or not. I can reference each checkbox by tileState[0], tileState[1], tileState[n], so it seems to mean the tileState is an array. However, if I try tileState.length, I get an error. So, I'm not sure if tileState is an array or not. Is there a way to loop through the tileState like you would an array?
let tileState = {}
tileItems.forEach((element, index) => {
tileState[index] = element.firstChild.value; // initial state
element.firstChild.onclick = (evt) => {
tileState[index] = !tileState[index];
console.log(`item ${index} :: ${tileState[index] ? "checked" : "unchecked"}`)
};
});
Answered! Go to the Best Answer.
Best Answer05-29-2019 11:05
05-29-2019 11:05
I declared the tileState as an array and that fixed the issue. I took the code from the manual and didn't know if there was a reason why the manual declares the tileState as an object.
Best Answer05-28-2019 11:10
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-28-2019 11:10
Can you provide a bit more code? You've declared tileState as an object in the example. Thanks
Best Answer05-28-2019 11:29
05-28-2019 11:29
This code came from the View Components Guide. I noticed tileState was declared as an object and not an array. I wasn't sure if there was a reason for doing it that way.
let tileState = {}
tileItems.forEach((element, index) => {
tileState[index] = element.firstChild.value; // initial state
element.firstChild.onclick = (evt) => {
tileState[index] = !tileState[index];
console.log(`item ${index} :: ${tileState[index] ? "checked" : "unchecked"}`)
};
});
Best Answer05-29-2019 11:05
05-29-2019 11:05
I declared the tileState as an array and that fixed the issue. I took the code from the manual and didn't know if there was a reason why the manual declares the tileState as an object.
Best Answer