Visualize multi-level response object as Table in Postman(在 Postman 中将多级响应对象可视化为表)
问题描述
我想将 Postman 测试中的以下数据可视化为一个表格,其中列中有 product、price 和 quantity,行中的项目.可能有多个 shippingGroups.
I would like to visualize the data below in Postman Tests as a Table with product, price and quantity in columns and Items in rows. There might be multiple shippingGroups.
{
   ...
   "companyGroups": [
        {
            ...
            "shippingGroups": [
                {
                    "id": 1,
                    "items": [
                        {
                            "product": "Product A",
                            "price": 2,
                            "quantity": 1,
                        },
                          {
                            "product": "Product B",
                            "price": 4,
                            "quantity": 4,
                        }
                    ],
                    ...
            ]
        }
    ],
我在使用 {{#each response???}} 引用多个级别对象中的项目时遇到问题.预期的格式应该是这样的:
I have trouble using the {{#each response???}} referring to items within multiple level objects. Expected format should be something like : 
   <table>
        <tr>
            <th>Product</th>
            <th>Price</th>
            <th>Quantity</th>
        </tr>
        {{#each response???}}
            <tr>
                <td>{{???product}}</td>
                <td>{{???price}}</td>
                <td>{{???quantity}}
            </tr>
        {{/each}}
    </table>
有关邮递员表可视化响应的更多信息此处
More info on Postman Table Visualizing Response here
推荐答案
鉴于您的响应示例,您可以使用如下内容:
Given your response example, you could use something like this:
const template = `
   <table>
        <tr>
            <th>Product</th>
            <th>Price</th>
            <th>Quantity</th>
        </tr>
        {{#each responseData}}
        {{#each items}}
            <tr>
                <td>{{product}}</td>
                <td>{{price}}</td>
                <td>{{quantity}}
            </tr>
        {{/each}}
        {{/each}}
    </table>
`;
let responseData = []
_.each(pm.response.json().companyGroups, (item) => {
    _.each(item.shippingGroups, (nestedItem) => {
        responseData.push(nestedItem)
    })
})
pm.visualizer.set(template, { responseData })
这只是一个粗略的示例,需要重构,但它表明您可以在表格中显示响应数据.
This is just a rough example and would need to be refactored but it shows that you can show the response data in the table.
这篇关于在 Postman 中将多级响应对象可视化为表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Postman 中将多级响应对象可视化为表
				
        
 
            
        - Flexslider 箭头未正确显示 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - addEventListener 在 IE 11 中不起作用 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 - Fetch API 如何获取响应体? 2022-01-01
 - 400或500级别的HTTP响应 2022-01-01
 - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 
						
						
						
						
						