1

我想将 Postman Tests 中的以下数据可视化为带有product、列和price行的表格。可能有多个 shippingGroups。quantityItems

{
   ...
   "companyGroups": [
        {
            ...
            "shippingGroups": [
                {
                    "id": 1,
                    "items": [
                        {
                            "product": "Product A",
                            "price": 2,
                            "quantity": 1,
                        },
                          {
                            "product": "Product B",
                            "price": 4,
                            "quantity": 4,
                        }

                    ],
                    ...
            ]
        }
    ],

我无法{{#each response???}}在多个级别对象中使用对项目的引用。预期的格式应该是这样的:

   <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>

有关邮递员表可视化响应的更多信息在这里

4

1 回答 1

1

鉴于您的响应示例,您可以使用以下内容:

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 })

这只是一个粗略的示例,需要重构,但它表明您可以在表中显示响应数据。

于 2020-04-15T12:30:28.067 回答