У меня есть массив объектов, которые я хочу отсортировать по имени.Я использую библиотеку lodash и использую _.sortBy ().Но с помощью этой функции я не получаю должного ответа.
Ниже мой массив activeUser
[ { date: 'Tue Dec 11 2018 00:00:00 GMT+0530 (IST)',
time: '10:30',
user_name: 'Happy Teachers DAy',
profilepic: 'http://192.168.0.109:8000//igXFkPIcNxSlhl0IB6c9iOexn.jpeg',
activeType: 'Group',
_id: '5b8f591bfd6e99021a2f1dd1',
isCreatedByTherapist: false,
groupMember: [] },
{ date: 'Tue Dec 11 2018 00:00:00 GMT+0530 (IST)',
time: '16:00',
user_name: 'Practice Group',
profilepic: null,
activeType: 'Group',
_id: '5bc1dce4b9d0faf0271e0ef5',
isCreatedByTherapist: false,
groupMember: [] },
{ date: 'Tue Dec 18 2018 00:00:00 GMT+0530 (IST)',
time: '16:00',
user_name: 'Practice Group',
profilepic: null,
activeType: 'Group',
_id: '5bc1dce4b9d0faf0271e0ef5',
isCreatedByTherapist: false,
groupMember: [] },
{ date: 'Sat Dec 15 2018 00:00:00 GMT+0530 (IST)',
time: '12:00',
user_name: 'Jayna',
profilepic: 'http://192.168.0.110:8000/D5sd646Tlx3zuOvWqhesSjIoL.jpeg',
activeType: 'Individual',
_id: '5b289024e019bb7623761bae',
isCreatedByTherapist: false,
groupMember: [] },
{ date: 'Fri Dec 12 2018 05:30:00 GMT+0530 (IST)',
time: '14:00',
user_name: 'GCK',
profilepic: 'http://192.168.0.110:8000/LDS3CpweCSSDDdOfa4lR6rPmn.jpeg',
activeType: 'Individual',
_id: '5ae1691241ce6c991f45b7fc',
isCreatedByTherapist: false,
groupMember: [] },
{ date: 'Fri Dec 11 2018 05:30:00 GMT+0530 (IST)',
time: '16:00',
user_name: 'kaushik',
profilepic: 'http://192.168.0.110:8000/DNAtiR1iiG2jgJWsIH5tpZCwv.jpeg',
activeType: 'Individual',
_id: '5b502b2724f36ada24167083',
isCreatedByTherapist: false,
groupMember: [] } ]
sortedName = _.sortBy (activeUser, ['user_name']);
Код groupBy указан ниже:
var date = function (d) {
if (d.fullname != null || d.fullname != undefined) {
return d.fullname.toUpperCase().charAt(0);
}
}
// map a group to the required form
var groupToSummary = function (group, date) {
return {
date: date,
data: group
}
}
var data = _(sortedName)
.groupBy(date)
.map(groupToSummary)
.value();
В sortedName я получаю следующий массив в качестве ответа:
[
{
"date": "G",
"data": [
{
"date": "Fri Dec 12 2018 05:30:00 GMT+0530 (IST)",
"time": "14:00",
"user_name": "GCK",
"profilepic": "http://192.168.0.110:8000/LDS3CpweCSSDDdOfa4lR6rPmn.jpeg",
"activeType": "Individual",
"_id": "5ae1691241ce6c991f45b7fc",
"isCreatedByTherapist": false,
"groupMember": []
}
]
},
{
"date": "H",
"data": [
{
"date": "Mon Dec 10 2018 00:00:00 GMT+0530 (IST)",
"time": "18:00",
"user_name": "Happy Teachers DAy",
"profilepic": "http://192.168.0.110:8000//igXFkPIcNxSlhl0IB6c9iOexn.jpeg",
"activeType": "Group",
"_id": "5b8f591bfd6e99021a2f1dd1",
"isCreatedByTherapist": false,
"groupMember": [
{
"groupMemberId": "5b46f08262efab2027ecce7a",
"_id": "5b90a8385ef8155c17865afc",
"isMultiSession": false
},
{
"groupMemberId": "5b502b2724f36ada24167083",
"_id": "5b90a8385ef8155c17865afb",
"isMultiSession": false
},
{
"groupMemberId": "5ae1691241ce6c991f45b7fc",
"_id": "5b90a8385ef8155c17865af9",
"isMultiSession": false
}
]
},
{
"date": "Tue Dec 11 2018 00:00:00 GMT+0530 (IST)",
"time": "10:30",
"user_name": "Happy Teachers DAy",
"profilepic": "http://192.168.0.110:8000//igXFkPIcNxSlhl0IB6c9iOexn.jpeg",
"activeType": "Group",
"_id": "5b8f591bfd6e99021a2f1dd1",
"isCreatedByTherapist": false,
"groupMember": [
{
"groupMemberId": "5b46f08262efab2027ecce7a",
"_id": "5b90a8385ef8155c17865afc",
"isMultiSession": false
},
{
"groupMemberId": "5b502b2724f36ada24167083",
"_id": "5b90a8385ef8155c17865afb",
"isMultiSession": false
},
{
"groupMemberId": "5ae1691241ce6c991f45b7fc",
"_id": "5b90a8385ef8155c17865af9",
"isMultiSession": false
}
]
}
]
},
{
"date": "J",
"data": [
{
"date": "Sat Dec 15 2018 00:00:00 GMT+0530 (IST)",
"time": "12:00",
"user_name": "Jayna",
"profilepic": "http://192.168.0.110:8000/D5sd646Tlx3zuOvWqhesSjIoL.jpeg",
"activeType": "Individual",
"_id": "5b289024e019bb7623761bae",
"isCreatedByTherapist": false,
"groupMember": []
},
{
"date": "Sat Dec 10 2018 05:30:00 GMT+0530 (IST)",
"time": "11:00",
"user_name": "Jayna",
"profilepic": "http://192.168.0.110:8000/D5sd646Tlx3zuOvWqhesSjIoL.jpeg",
"activeType": "Individual",
"_id": "5b289024e019bb7623761bae",
"isCreatedByTherapist": false,
"groupMember": []
}
]
},
{
"date": "P",
"data": [
{
"date": "Tue Dec 11 2018 00:00:00 GMT+0530 (IST)",
"time": "16:00",
"user_name": "Practice Group",
"profilepic": null,
"activeType": "Group",
"_id": "5bc1dce4b9d0faf0271e0ef5",
"isCreatedByTherapist": false,
"groupMember": []
}
]
},
{
"date": "K",
"data": [
{
"date": "Fri Dec 11 2018 05:30:00 GMT+0530 (IST)",
"time": "16:00",
"user_name": "kaushik",
"profilepic": "http://192.168.0.110:8000/DNAtiR1iiG2jgJWsIH5tpZCwv.jpeg",
"activeType": "Individual",
"_id": "5b502b2724f36ada24167083",
"isCreatedByTherapist": false,
"groupMember": []
}
]
}
]
Как видите, последние два объекта не являются правильными !!
Пожалуйста, помогите мне !!!Любая помощь будет оценена !!!