I am a bit stuck with reformatting tempState data back into an array to display it properly in a table.
My app setup is simply: A user can query our API for products, select one product from a table to add this product then to a "Selection table" on the right.
I am using tempState to save each selection in chronological order. Here is the example for two entries:
I have used map() to structure the data into an array to display it properly in the right selection table. The only working version I managed so far is to access one single entry and to display it properly:
How can I iterate through each key of my tempState to display the two product of my example in my selection table? I have tried a FOR loop and different variants with MAP etc. somehow I have been running in circles for over 2h. Does anybody have a hint?
So the table shows me the those four values per cell in two columns, instead of mapping four values in four separate column with two rows. What am I missing here?
Ahh! I see. I was truly puzzled at how the table was displaying the data like that.
You have [{{stateProduct.value}}] in your data propertty. Get rid of the square brackets and make it {{stateProduct.value}}. I think you have that left over from your earlier attempt and this new method makes that unneeded.
Thanks for the hint. That's what I thought too. However, retool claims its not an array of objects, and believe me I formatted this array every possible way.
Here is the output from the JSON editor of {{stateProduct.value}}
Trying to useformatDataAsArray() is just leaving me an empty array
What am I overlooking here? Probably its just a simple mistake ....
Ok, I figured it out:
The problem was that I initialized my tempState variable as an empty Object {}. It works now by simply switching it to an empty Array []. The saved data is now displayed correctly.
Anyhow, it would be interesting to know why formatDataAsArray() is not working in above problem setting, or how to reformat such data accordingly for future cases.