我想根据“标题”和"alertID“在JSON下面分组,然后按升序或降序排序。
let events = [{
"_id": "5cbdb030284dfeb0bb441bfe",
"alert": {
"title": "New Pt w/ discharge in last 30 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "99994444"
}
}, {
"_id": "5cbdafbc284dfeb0bb441bd7",
"alert": {
"title": "Insurance: Non-Contracted Plan",
"alertTime": "2018-09-01T03:13:00.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdafbe284dfeb0bb441be6",
"alert": {
"title": "Insurance: Non-Contracted Plan",
"alertTime": "2018-09-01T03:13:00.000Z",
"alertID": "12345688"
}
}, {
"_id": "5cbdb08d284dfeb0bb441c13",
"alert": {
"title": "New Pt w/ ED visit in last 7 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdb068284dfeb0bb441c09",
"alert": {
"title": "New Pt w/ ED visit in last 7 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "12345688"
}
}, {
"_id": "5cbdb477284dfeb0bb441c73",
"alert": {
"title": "PT Consult Order",
"alertTime": "2018-07-17T05:42:15.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdafb8284dfeb0bb441bc7",
"alert": {
"title": "Bed Request Order for Medicare Patient",
"alertTime": "2019-04-22T12:12:39.340Z",
"alertID": "99994444"
}
}]这就是我如何实现(降序),但它没有得到排序。
_(events)
.orderBy(events, (e) => { return e.alert.alertTime},['desc'])
.uniqBy(function(event) { return [event.alert.title, event.alert.alertID].join();})
.groupBy((event) => event.alert.alertID)我特别想利用房客来达到这一要求。有人能指出我错过了什么吗?
--这是我所期望的输出。因此,如果"alertID: 99994444“首先出现,那么我想对所有具有相同'alertID‘的数据进行分组,并按升序或降序排序,如下所示。同样,对于所有剩余的“警报be”,都应该这样做。:
[{
"_id": "5cbdb477284dfeb0bb441c73",
"alert": {
"title": "PT Consult Order",
"alertTime": "2018-07-17T05:42:15.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdafbc284dfeb0bb441bd7",
"alert": {
"title": "Insurance: Non-Contracted Plan",
"alertTime": "2018-09-01T03:13:00.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdb08d284dfeb0bb441c13",
"alert": {
"title": "New Pt w/ ED visit in last 7 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "12345699"
}
}, {
"_id": "5cbdafbe284dfeb0bb441be6",
"alert": {
"title": "Insurance: Non-Contracted Plan",
"alertTime": "2018-09-01T03:13:00.000Z",
"alertID": "12345688"
}
}, {
"_id": "5cbdb068284dfeb0bb441c09",
"alert": {
"title": "New Pt w/ ED visit in last 7 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "12345688"
}
}, {
"_id": "5cbdb030284dfeb0bb441bfe",
"alert": {
"title": "New Pt w/ discharge in last 30 days",
"alertTime": "2018-12-15T05:48:31.000Z",
"alertID": "99994444"
}
}, {
"_id": "5cbdafb8284dfeb0bb441bc7",
"alert": {
"title": "Bed Request Order for Medicare Patient",
"alertTime": "2019-04-22T12:12:39.340Z",
"alertID": "99994444"
}
}]发布于 2019-04-25 11:14:34
问题是,在使用_(events)链接时,应该省略链式方法调用中的第一个“集合”参数。因此,改变:
_(events)
.orderBy(events, (e) => { return e.alert.alertTime},['desc'])至:
_(events)
.orderBy((e) => { return e.alert.alertTime},['desc'])https://stackoverflow.com/questions/55847771
复制相似问题