I am able to filter the bookings
based on b.building.id
here:
bookings.filter(b => b.building.id == this.filter.buildingId);
However, I am struggling to filter the bookings
object array if the b.modules
is also an array. Here is my unsuccessful attempt:
bookings.filter(b => b.modules.programme.facultyId == this.filter.facultyId);
And another unsuccessful attempt:
bookings.filter(b => {
for (let module of b.modules) {
module.programme.facultyId == this.filter.facultyId;
}
});
Update:
Below is an example of a JSON result for bookings
:
[
{
"id": 2,
"semesterId": 1,
"room": {
"capacity": 17,
"code": null,
"building": {
"id": 5,
"name": "Faculty of Science"
},
"id": 15,
"name": "FSB 1.10"
},
"building": {
"id": 5,
"name": "Faculty of Science"
},
"bookDate": "2020-11-10T00:00:00",
"timeSlots": [
{
"id": 1,
"startTime": "1900-01-01T07:50:00",
"endTime": "1900-01-01T08:40:00"
},
{
"id": 2,
"startTime": "1900-01-01T08:50:00",
"endTime": "1900-01-01T09:40:00"
}
],
"modules": [
{
"id": 5,
"name": "Computer Systems and Information Technology",
"code": "SS-1202",
"lecturers": [
{
"id": 4,
"name": "Lim",
"title": "Dr."
}
],
"programme": {
"id": 1,
"name": "Computer Science",
"shortName": null,
"facultyId": 1
}
}
]
}
]