【发布时间】:2020-08-21 06:43:20
【问题描述】:
我看到文档说
Multi-value .*keyName Array of values of any matching keys
Descendants ..keyName Array of values of any matching descendant keys
但我还是不明白其中的区别。
【问题讨论】:
我看到文档说
Multi-value .*keyName Array of values of any matching keys
Descendants ..keyName Array of values of any matching descendant keys
但我还是不明白其中的区别。
【问题讨论】:
Descendant 返回一个对象的每个嵌套级别中第一次出现的键的数组。 多值返回一个对象的当前嵌套级别中所有出现的键的数组。
如果你有这个输入:
{
"id": 1,
"id": 11,
"secondLevel": {
"id": 2,
"id": 22,
"thirdLevel": {
"id": 3,
"id": 33
}
}
}
还有这个脚本:
%dw 2.0
output application/json
---
{
"descendant": payload..id, //first occurrence of "id" in each level
"multivalue": payload.*id, //all occurrence of "id" in the current level (the first level)
"multivalueSecondLevel": payload.secondLevel.*id, //all occurrence of "id" in the current level (the second level)
"allTheIds" : payload..*id //all the ID (descendant with multivalue)
}
它将生成以下输出:
{
"descendant": [
1,
2,
3
],
"multivalue": [
1,
11
],
"multivalueSecondLevel": [
2,
22
],
"allTheIds": [
1,
11,
2,
22,
3,
33
]
}
更多详情https://docs.mulesoft.com/mule-runtime/4.2/dataweave-cookbook-extract-data#descendants
【讨论】:
我觉得用例子来解释很容易,所以基于this one你会得到下一个结果:
payload.breakfast_menu.food -> First food element
payload.breakfast_menu.*food -> List of food elements
payload.breakfast_menu.*name -> Nothing
payload.breakfast_menu..name -> List of all product name values
【讨论】: