[英]How to display data in the form list in list using Adonisjs
I have a data that only one list, i want to display this data like list in the list,我有一个只有一个列表的数据,我想在列表中显示此数据,如列表,
this is my query and how i returned it:这是我的查询以及我如何返回它:
const cart = await DB
.select('carts.id_cart','carts.id_product','product.shop_id','product.product_name','product.price',
'shop.shop_name','shop.address', DB.raw('count(carts.id_product) as quantity'))
.from('carts')
.leftJoin('product', 'carts.id_product', 'product.product_id')
.leftJoin('shop', 'shop.id_shop', 'product.shop_id')
.groupBy('carts.id_product')
.where({'product.is_deleted':'0'})
return response.json({
status:true,
message: false,
data: cart
})
And result of this code like this:这段代码的结果是这样的:
{
"status": true,
"message": false,
"data": [
{
"id_cart": "1",
"id_product": "1",
"shop_id": "1",
"product_name": "test1",
"price": 11111,
"shop_name": "John Doe",
"address": "Quis et eu cumque Na",
"quantity": 1
}
]
I want the result changed like this:我希望结果改变如下:
[
"status": true,
"message": false,
"data": [
{
"id_cart": "1",
"shop_id" : "1",
"product" : [
{
"id_product": "1",
"product_name": "test1",
"price": 11111,
"shop_name": "John Doe",
"address": "Quis et eu cumque Na",
"quantity": 1
}
]
}
]
]
Anyone can help me?任何人都可以帮助我吗?
The support for same has been added.添加了对相同的支持。 to do a nested query builder in AdonisJs在 AdonisJs 中做一个嵌套查询构建器
.whereHas
and .has
is help to you and see this link: Inject new data into query object .whereHas
和.has
对您有帮助,请参阅此链接: Inject new data into query object
in query we use jsonb_agg
and jsonb_build_object
when to make nested object.在查询中,我们使用jsonb_agg
和jsonb_build_object
来制作嵌套的 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.