我有一组订单,并希望生成带有订单的html文档,我想使用解析模板,但我不知道这对于有效负载中的多个订单项是如何工作的。我想生成这样的东西:
<html>
<body>
<table border=4>
<tr>
<th>Order No</th>
<th>Order Description</th>
<th>Provisioning Date</th>
</tr>
<tr>
<td>#[payload[0]['order_no']]</td>
<td>#[payload[0]['order_description']]</td>
<td>#[payload[0]['provisioning_date']]</td>
</tr>
<tr>
<td>#[payload[1]['order_no']]</td>
<td>#[payload[1]['order_description']]</td>
<td>#[payload[1]['provisioning_date']]</td>
</tr>
...... to n orders
</table>
</body>
</html>
这就是我想要实现的目标。如何使用parse-template实现此目的?
答案 0 :(得分:1)
使用MEL(Mule表达式语言),您可以遍历每个订单并构建所需的html和动态值。
#[
String orders = "";
for(int i = 0; i < payload.size(); i++) {
orders += "<tr>";
orders += "<td>" + payload[i]['order_no'] + "</td>";
orders += "<td>" + payload[i]['order_description'] + "</td>";
orders += "<td>" + payload[i]['provisioning_date'] + "</td>";
orders += "</tr>"
}
return orders;
]
答案 1 :(得分:0)
您可以使用javascript循环解析模板:
var addressList = #[payload]
for (var i = 0; i < payload.length; i++)
document.getElementById('table').innerHTML += '<tr><td>' + addressList
[i].order_no + '</td><td>' + addressList [i].order_description + '</td>
<td>' + addressList[i].provisioning_date + '</td></tr>'