在循环数据编织中过滤相同级别的对象值 - Mule 3.7

Filter same level object values in loop data weave - Mule 3.7

我正在尝试在 Dataweave 的有效负载中过滤相同级别的对象值。我能够循环,但它没有产生预期的输出。 示例负载:

{
    "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
         }

        }

        )
        )
    }
}

如何实现?

谢谢, 资产回报率

试试这个:

%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中的是字符串