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 AnswerI 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
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.
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 AnswerI 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