我正试图将一个json阵列转换到(以表格格式)在MuleSoft使用2.0数据。 我的投入有效载荷就是这样:
[
{
"Product ID": "4d5c0b68",
"Product Number": "be56",
"Product Name": "Product A",
"Product Priority": "High Risk",
"Product Attachments": 2,
"Combo?": "No"
}
]
我需要的html产出如下:
<table style="width: 50%; border: 1px solid black; font-family: Monospace">
<tr bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">Product ID</th>
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid blue; font-size:14px; ">Product Number</th>
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">Product Name</th>
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">Product Priority</th>
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">Product Attachments</th>
<th bgcolor="#6c7ae0" style="color: white !important;border: 1px solid black; font-size:14px; ">Combo?</th>
</tr>
<tr align="center" style="color: #666666; font-size:12px; border: 1px solid black; font-weight: 500; width:10%">
<td style="color: black !important;border: 1px solid black; font-size:14px; ">4d5c0b68</td>
<td style="color: black !important;border: 1px solid black; font-size:14px; ">be56</td>
<td style="color: black !important;border: 1px solid black; font-size:14px; ">Product A</td>
<td style="color: black !important;border: 1px solid black; font-size:14px; ">High Risk</td>
<td style="color: black !important;border: 1px solid black; font-size:14px; ">2</td>
<td style="color: black !important;border: 1px solid black; font-size:14px; ">No</td>
</tr>
</table>
The json data currently given is for only 1 row and I will have to map the whole array in the html. Can this be achieved using dataweave 2.0?
这就是我目前的情况。
%dw 2.0
output application/xml writeDeclaration=false
var tableData = payload map ((item, index) ->
{
"Product ID" : item.ProductID,
"Product Number": item.ProductNumber,
"Product Name": item.ProductName,
"Product Priority": item.ProductPriority,
"Product Attachments": item.ProductAttachments as Number,
"Combo?" : if (item.Combo == "false") "No" else "Yes"
})
var headerRow = [
{
"header": "Product ID",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
},
{
"header": "Product Number",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
},
{
"header": "Product Name",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
},
{
"header": "Product Priority",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
},
{
"header": "Product Attachments",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
},
{
"header": "Combo?",
"style": "color: white !important; border: 1px solid black; font-size: 14px;"
}
]
---
<table style="width: 50%; border: 1px solid black; font-family: Monospace">
<tr bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">Case #</th>
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid blue; font-size: 14px;">Interaction #</th>
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">Product Name</th>
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">PQC Priority</th>
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">No. of PQC Attachments</th>
<th bgcolor="#6c7ae0" style="color: white !important; border: 1px solid black; font-size: 14px;">Combo?</th>
</tr>
<tr align="center" style="color: #666666; font-size: 12px; border: 1px solid black; font-weight: 500; width: 10%">
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Product ID")}</td>
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Product Number")}</td>
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Product Name")}</td>
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Product Priority")}</td>
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Product Attachments")}</td>
<td style="color: black !important; border: 1px solid black; font-size: 14px;">{(tableData[0]."Combo?")}</td>
</tr>
</table>