Dynamically select the Id of an object

Hey guys!

How can I make it take the ID/Key of each object so that it is dynamic?

In the screenshot I put it manually, as the autocomplete suggests, however I need it to be taken dynamically.

Already tried with: [i]

{{ Messages.data[i].idCustomer > '1' ......

Already tried with: [0]

{{ Messages.data[0].idCustomer > '1' ......

However I can't get it to work correctly. :upside_down_face:

Thank you very much for your time.

@Kabirdas I see that you are part of the Retool team, sorry for tagging you.

I would like to know if you can help me explain how to solve this detail.

Maybe it's something quite simple that I'm going unnoticed

Hmm... you could try using something like Object.values on your query data to convert it into any array of message objects. That could be done, for instance, by adding a transformer to your query that looks something like:

return Object.values(data);

Which would turn your query data into something like

[
  {
    idCustomer: 5624196464,
    messageBody: "Hola soy el cliente",
    messageTime: 1669348678,
    messageType: "text"
  },
  {
   /* second message */
  },
  // ... etc
]

In that case, you could access each value using i exactly the way you did in your first example (assuming this HTML component is in a listview).

If it's important to keep the keys as well, you can try Object.entries instead:

return Object.entries(data);

Which would turn your data into something like:

[
  [ 
    849834389438943894383498439120921,
    {
      idCustomer: 5624196464,
      messageBody: "Hola soy el cliente",
      messageTime: 1669348678,
      messageType: "text"
    }
  ],
  [
    930983740192783491023741234,
    {
      /* second message */
    }
  ],
  // ... etc
]

That would in which case you'd access each value with something like

{{ Messages.data[i][1].idCustomer > '1' ...

That 1 would be fixed since the actual message object would always be the second object in its corresponding array.

Let me know if that helps!