Use case: adding behavior
For this part of our e-commerce use case, let’s work on rendering a cart page of items. In this case, we will mock calling a backend for the data and let the data be placed in a file called cart.json
with the following structure:
{
"cart": [
]
}
The above JSON content describes a JSON object (defined by {}
), with the property cart
, of the array type, as denoted by the square brackets, []
.
In fact, let’s use our AI assistant to generate the data we need. Let’s create the cart.json
file and the following structure and prompt:
{
"cart": [
// item with id name , quantity and price, total = quantity * price
]
}
Note the prompt // item with id name, quantity and price, total = quantity * price
, which results in the following JSON:
{
"id": "1",
"name": "item1",
"quantity": "1",
"price": "10...