Dataweave通过另一个数组值过滤数组

时间:2020-07-23 00:19:15

标签: mule dataweave mulesoft

我想根据另一个数组值过滤一个数组。我想基于键值“ KNVP-PARVW”过滤输入数组,该值在[“ BP,SH,PY”]列表中

这是输入:

[{
    "KNVP-KUNNR": "100098",
    "KNVP-VTWEG": "A1",
    "KNVP-PARVW": "BP",
    "KNVP-PARZA": "000",
    "KNVP-KUNN2": "200115",
    "KNVP-DEFPA": ""
  },
  {
    "KNVP-KUNNR": "100098",
    "KNVP-VTWEG": "A1",
    "KNVP-PARVW": "SH",
    "KNVP-PARZA": "001",
    "KNVP-KUNN2": "200115",
    "KNVP-DEFPA": ""
  },
  {
    "KNVP-KUNNR": "100098",
    "KNVP-VTWEG": "A1",
    "KNVP-PARVW": "ZR",
    "KNVP-PARZA": "000",
    "KNVP-KUNN2": "256",
    "KNVP-DEFPA": ""
  }]

这是我的数据编织代码:

%dw 2.0
var relationList=["BP,SH,PY"]
output application/json
---
payload filter (  relationList contains  $."KNVP-PARVW" )

2 个答案:

答案 0 :(得分:2)

虽然["BP,SH,PY"]是一个列表,但只有一个元素是字符串。要按预期使用contains(),它必须是$."KNVP-PARVW"的有效值的列表:

%dw 2.0
var relationList=["BP","SH","PY"]
output application/json
---
payload filter (  relationList contains  $."KNVP-PARVW" )

输出:

[
  {
    "KNVP-KUNNR": "100098",
    "KNVP-VTWEG": "A1",
    "KNVP-PARVW": "BP",
    "KNVP-PARZA": "000",
    "KNVP-KUNN2": "200115",
    "KNVP-DEFPA": ""
  },
  {
    "KNVP-KUNNR": "100098",
    "KNVP-VTWEG": "A1",
    "KNVP-PARVW": "SH",
    "KNVP-PARZA": "001",
    "KNVP-KUNN2": "200115",
    "KNVP-DEFPA": ""
  }
]

答案 1 :(得分:-1)

得到var relationshipList应该如下所示

var relationList="BP,SH,PY"