简体   繁体   English

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

[英]Construct String from Array in Dataweave 2.0

I am on Mule 4. I need to create a "filter string" (to be used in an API call) from an array.我在 Mule 4 上。我需要从数组中创建一个“过滤字符串”(用于 API 调用)。 A sample input array is given below:下面给出了一个示例输入数组:

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

I need to get an output string like this using dataweave 2.0 ID = '123AAA#DT' OR ID = '123BBB#DT' OR ID = '123CCC#DT' OR ID = '123DDD#DT' OR ID = '123EEE#DT'我需要使用 dataweave 2.0 ID = '123AAA#DT' OR ID = '123BBB#DT' OR ID = '123CCC#DT' OR ID = '123DDD#DT' OR ID = '123EEE#DT'

I tried using joinBy function but since this is in an array, it was giving an error.我尝试使用 joinBy function 但由于它在数组中,因此出现错误。 Please advise.请指教。

It seems a good candidate for reduce ().它似乎是reduce () 的好候选。

%dw 2.0
output application/json
---
payload reduce ((item, accumulator="") -> "ID = '" ++ item ++ "#DT'" ++ (if (accumulator != "")  " OR " ++ accumulator else "" ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM