简体   繁体   English

如何使用 Adonisjs 在列表中的表单列表中显示数据

[英]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_aggjsonb_build_object来制作嵌套的 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PHP在表单的下拉列表中显示来自MySQL的数据? - How to display data from MySQL in the drop down list on the form using PHP? 如何在列表中显示MySQL数据 - How to display MySQL data in a list 在adonisjs中使用关系返回数据是null - Return data using relation in adonisjs is null 如何将mysql中数据库中的数据或表格显示为ms访问形式可编辑? (像列表框一样可编辑) - How to display the data or table in database in mysql as editable in ms access form? (Like List box as editable ) 如何在 Html 表单上显示数据列表 - How to Show List of Data on Html Form 使用PHP使用下拉列表显示数据库中的数据 - using PHP to display data from database using a dropdown list 无法显示列表内容/未添加到列表的数据 - Not able to display contents of List/ data not added to list 如何使用下拉列表从数据库获取数据并显示到php mysql中的输入字段中? - How to get data from database using drop down list and display into input fields in php mysql? 如何使用struts2和mysql在下拉列表中的jsp页面上显示从数据库中获取的数据 - How display data fetched from database on a jsp page in dropdown list using struts2 with mysql 如何在 CAKEPHP 3 中其他表的下拉列表中显示数据? - HOW TO DISPLAY DATA IN DROP DOWN LIST FROM OTHER TABLE IN CAKEPHP 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM