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 中将多级响应对象可视化为表


基础教程推荐
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01