gpt4 book ai didi

Mule Dataweave 按多个值排序

转载 作者:行者123 更新时间:2023-12-02 04:00:48 25 4
gpt4 key购买 nike

我想知道如何使用 Dataweave orderBy 对 mule 中的集合进行排序,其中包含多个字段以及升序或降序。

最佳答案

这是我创建的示例代码(带有示例),用于演示多个 orderby 和排序。注意:- 默认情况下,排序依据是升序,要实现降序排列,只需将末尾的结果反转[-1..0]即可。

%dw 1.0
%var inputPayload=[
{"name":"john",
"age": "12"
},
{"name":"john3",
"age": "15"
},
{"name":"john3",
"age": "14"
},
{"name":"john1",
"age": "13"
},
{"name":"john2",
"age": "14"
},

{"name":"john5",
"age": "17"
}

]


%output application/json
---
((inputPayload orderBy $.name) orderBy $.age)[-1..0]

Output Payload - [ { "name": "john5", "age": "17" }, { "name": "john3", "age": "15" }, { "name": "john3", "age": "14" }, { "name": "john2", "age": "14" }, { "name": "john1", "age": "13" }, { "name": "john", "age": "12" } ]

关于Mule Dataweave 按多个值排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42021908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com