Get value from Data Store

Hey guys,

In my app I have a cart that is using a data store.
I have multiple lines like:

{"records":[{"$id":1,"product_id":"4","product_name":"Planche de SUP","date_start":"2024-09-27","date_end":"2024-10-04","qty":2,"unit_price":15,"total_price":240},{"$id":2,"product_id":"4","product_name":"Planche de SUP","date_start":"2024-09-27","date_end":"2024-10-04","qty":2,"unit_price":15,"total_price":240}],"lastid":2}

In a page I need to be able to get the quantity (qty) of product_id=4 or any other id

Is there an easy way of doing this? I have written a js function but I would prefer to use wapppler's components.

Thank you

Hi Stefdec,

The data store fields are available to dynamically pick in the UI, similar to a server connect.

This is an example of a data store with a where clause to filter data by a selected product_id in the datastore and get a value of the ds_order_qty.

ds_shoppingcart.data.where(`ds_product_id.toNumber()`, product_id, '==')[0].ds_order_qty
1 Like

Thanks, sometimes I really go too far when the solution is so simple :joy:
I used a data detail and problem solved

1 Like

I tend to overthink too :slightly_smiling_face:

Yes, data detail is a great solution to filter and get data from a single value. I use it extensively in my apps.

Note you accidentally put two dots in your code example before “where”…

1 Like

Thanks for alerting me for the mistake, Antony.

I have corrected the code now. :slight_smile: