在Dataweave中,选择器..和。*之间有什么区别?

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

我看到文档说

Multi-value  .*keyName  Array of values of any matching keys
Descendants  ..keyName  Array of values of any matching descendant keys

但是我仍然不明白区别。

dataweave mulesoft
2个回答
0
投票
[我认为喜欢使用示例进行解释很容易,因此基于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


0
投票
多值返回一个数组,该数组包含在对象的当前嵌套级别中所有出现的键。后代返回在对象的每个嵌套级别中第一次出现的键的数组

如果有此输入:

{ "id": 1, "id": 11, "secondLevel": { "id": 2, "id": 22, "thirdLevel": { "id": 3, "id": 33 } } }

和此脚本:

{ "allTheId" : payload..*id, //all the ID "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) }

它将生成此输出:

{ "allTheId": [ 1, 11, 2, 22, 3, 33 ], "descendant": [ 1, 2, 3 ], "multivalue": [ 1, 11 ], "multivalueSecondLevel": [ 2, 22 ] }

https://docs.mulesoft.com/mule-runtime/4.2/dataweave-cookbook-extract-data#descendants中的更多详细信息
© www.soinside.com 2019 - 2024. All rights reserved.