So I have a JSON
object of an array of objects that looks something like this:
[
{
"id": 0,
"name": "Sophia Mason",
"availability": [
{
"date": 1522216800000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
...
],
},
.........
]
I have another array of days rendered using moment.js
that looks something like this:
[1522216800000, 1522303200000, 1522389600000]
I need to filter the first array of objects availability by the day in each index of the date array. Then render each photographer in each day correctly in a calendar.
I am using AngularJS (by request of the client) to make something that looks like this:
I already have the days rendering by using Moment, but I am having trouble figuring out how to show each photographer per day based on their availability. To look like the calendar above.
I may be overthinking this but I have been trying to figure this out for the last few hours. Here are some of the many 'similar' answers I have looked through:
Which has me only thinking of something that looks like this in my controller.js
:
function setPhotographers() {
let photographer = photographers.filter((el) => {
el.availability.some((availability) => availability.date === today)
.map((el)=> {
console.log(el);
let newEl = Object.assign({}, el);
return newEl.availability.filter(availability => availability.date === today);
});
});
return photographer;
}
I am still am learning a lot but this has me pretty stuck. Any help would be great! Please if you have an answer to describe why your solution works to help me better understand what you did to accomplish this.
Thanks!
You're on the right track with the .filter()
, I'm not sure why you need the .map()
. The following should be sufficient to get you a filtered array of photographers with availability matching the today
variable.
let availablePhotographers = photographers.filter((el) => el.availability.some((availability) => availability.date === today))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.