在Dataweave 2.0中从数组中构造字符串。

问题描述 投票:0回答:1

我在Mule 4上。我需要从一个数组中创建一个 "过滤字符串"(用于API调用)。下面给出了一个输入数组的示例。

[
  "123AAA","123BBB","123CCC","123DDD","123EEE"
]

我需要用dateave 2.0得到一个像这样的输出字符串。ID = '123AAA#DT' OR ID = '123BBB#DT' OR ID = '123CCC#DT' OR ID = '123DDD#DT' OR ID = '123EEE#DT'

我试着使用joinBy函数,但由于这是在一个数组中,它给出了一个错误。请赐教。

mule mule-studio dataweave mule-component anypoint-studio
1个回答
2
投票

这似乎是一个很好的候选人 减少().

%dw 2.0
output application/json
---
payload reduce ((item, accumulator="") -> "ID = '" ++ item ++ "#DT'" ++ (if (accumulator != "")  " OR " ++ accumulator else "" ))
© www.soinside.com 2019 - 2024. All rights reserved.