在循环数据编织中过滤相同级别的对象值-Mule 3.7
我试图在Dataweave中过滤有效负载中的相同级别对象值。我能够循环,但它不能产生预期的输出。 样本有效载荷:在循环数据编织中过滤相同级别的对象值-Mule 3.7,mule,dataweave,Mule,Dataweave,我试图在Dataweave中过滤有效负载中的相同级别对象值。我能够循环,但它不能产生预期的输出。 样本有效载荷: { "root": { "createItem": { "itemInfo": { "lines": [{ "lineIdentifier": "4", "Attributes": "Test1",
{
"root": {
"createItem": {
"itemInfo": {
"lines": [{
"lineIdentifier": "4",
"Attributes": "Test1",
"partNumber": "QZRB"
}, {
"lineIdentifier": "10",
"Attributes": "Test3",
"partNumber": "QPR1"
}, {
"lineIdentifier": "12",
"Attributes": "Test4",
"partNumber": "QHT2"
}]
}
},
"ItemResponse": {
"lines": [{
"lineIdentifier": 4,
"itemName": "QZRB",
"status": "FAILED"
}, {
"lineIdentifier": 10,
"itemName": "QPR1",
"status": "COMPLETE"
}, {
"lineIdentifier": 12,
"itemName": "QHT2",
"status": "COMPLETE"
}]
}
}
}
预期产出:
{
"root": {
"createItem": {
"itemInfo": {
"lines": [ {
"lineIdentifier": "10",
"Attributes": "Test3",
"partNumber": "QPR1"
}, {
"lineIdentifier": "12",
"Attributes": "Test4",
"partNumber": "QHT2"
}]
}
}
}
}
以下是我正在做的:
{
root: {
(payload.root.createItem.itemInfo.lines map ((respLines, indexOfRespLines) -> {
items:payload.root.ItemResponse.lines filter ($.itemName == respLines.partNumber and $.status =='COMPLETE') map
{
item: $.itemName,
attributes: respLines.Attributes
}
}
)
)
}
}
我如何做到这一点
谢谢,
ROA试试这个:
%dw 1.0
%output application/json
%var completedLines = payload.root.ItemResponse.lines filter $.status == 'COMPLETE' map $.lineIdentifier as :string
---
{
root: {
createItem: {
itemInfo: {
lines: payload.root.createItem.itemInfo.lines filter (completedLines contains $.lineIdentifier)
}
}
}
}
请注意completedLines
中的as:string
,因为ItemResponse
中的lineIdentifier
是一个数字,而itemInfo
中的是一个字符串。尝试以下操作:
%dw 1.0
%output application/json
%var completedLines = payload.root.ItemResponse.lines filter $.status == 'COMPLETE' map $.lineIdentifier as :string
---
{
root: {
createItem: {
itemInfo: {
lines: payload.root.createItem.itemInfo.lines filter (completedLines contains $.lineIdentifier)
}
}
}
}
请注意
completedLines
中的as:string
,因为ItemResponse
中的lineIdentifier
是一个数字,而itemInfo
中的是一个字符串。您好,谢谢您的回复。下面是我得到的回答:{“root”:{“foo”:[10,12],“createItem”:{“itemInfo”:{“lines”:[]}}}}}内部筛选器似乎没有获得所需的数据。我假设您的输入数据与您最初的问题中的数据不同。lineIdentifier很可能不是字符串,而是数字。然后您必须删除as:string
。顺便说一句:我忘了删除foo:)嗨,是的,对不起。它们是字符串。但它仍然不起作用。有什么建议吗?@ROA恐怕你必须提供更多的细节,因为对我来说,上面的dataweave工作正常。你能上传一个示例mule应用程序到github吗?嗨,是的,谢谢你的回复。下面是我得到的回答:{“root”:{“foo”:[10,12],“createItem”:{“itemInfo”:{“lines”:[]}}}}}内部筛选器似乎没有获得所需的数据。我假设您的输入数据与您最初的问题中的数据不同。lineIdentifier很可能不是字符串,而是数字。然后您必须删除as:string
。顺便说一句:我忘了删除foo:)嗨,是的,对不起。它们是字符串。但它仍然不起作用。有什么建议吗?@ROA恐怕你必须提供更多的细节,因为对我来说,上面的dataweave工作正常。您可以将示例mule应用程序上载到github吗?