我在dataweave中有一个数组让我们说
[value1,value2,value3,value4]
我想在数组中获取我的值的索引。假设我想知道哪个索引位置' value2'存在,它应该返回2.
**code I tried:**
%dw 1.0
%output application/xml
%var myArray =[] as :array
---
{
root: using (myArray = payload.values.*value distinctBy $) {
(payload.values.*value map{
position: "needs logic to get position of current value in the myArray created"
})
}
**input:**
<values>
<value>value1</value>
<value>value2</value>
<value>value3</value>
<value>value4</value>
<value>value1</value>
<value>value3</value>
</values>
expected output:
<root>
<position>1<position>
<position>2<position>
<position>3<position>
<position>4<position>
<position>1<position>
<position>3<position>
<root>
答案 0 :(得分:1)
关于:
%dw 1.0
%output application/xml
%var myArray =[] as :array
---
{
root: using (myArray = payload.values.*value distinctBy $) {
(payload.values.*value map (
position: $$
)) }
}
输出:
<?xml version='1.0' encoding='UTF-8'?>
<root>
<position>0</position>
<position>1</position>
<position>2</position>
<position>3</position>
<position>4</position>
<position>5</position>
</root>