本文介绍了Dataweave 2.0 maxBy和过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用一个最大值过滤一个数组,并让它返回具有该值的所有元素.Dataweave刚返回1.
I'd like to filter an array by a maximum value, and have it return all elements with that value. Dataweave is just returning 1.
这是Mule 4上的dataweave 2.0.首先,应该有一个groupBy来对具有相同ID的元素进行分组.然后,应该在每个元素组中搜索最大的check_date,并且只应返回每个具有该日期的元素组中的内容.
This is dataweave 2.0 on Mule 4. First, there should be a groupBy to group elements with the same id. Then, within each element group, there should be a search for the largest check_date, and only those within each element group with that date should be returned.
%dw 2.0
output application/json
var arr = [
{
"id": "001P000001MPf0XIAT",
"code": "580",
"type": "M",
"check_date": "2017-09-08T12:00:00"
},
{
"id": "001P000001MjaVOIAZ",
"code": "ZN1",
"type": "A",
"check_date": "2018-05-01T12:00:00"
},
{
"id": "001P000001MjaVOIAZ",
"code": "ZN1",
"type": "M",
"check_date": "2018-05-01T12:00:00"
},
{
"id": "001P000001MjaVOIAZ",
"code": "ZN1",
"type": "A",
"check_date": "2017-11-01T12:00:00"
},
{
"id": "001P000001MPf0XIAT",
"code": "580",
"type": "M",
"check_date": "2019-04-12T12:00:00"
}
]
---
arr groupBy $.id mapObject (value,key) -> {
grouping:{
id:key,
rows:value maxBy $.check_date
}
}
推荐答案
rows: value filter ((item, index) ->
item.check_date == (value maxBy $.check_date).check_date)
这篇关于Dataweave 2.0 maxBy和过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!