Modifier le code : https://github.com/dupontdenis/fetch.git
Pour afficher à partir de https://ghibliapi.herokuapp.com/films
H. Miyazakis's Films
- The Red Turtle : Michaël Dudok de Wit
- When Marnie Was There : Hiromasa Yonebayashi
- The Tale of the Princess Kaguya : Isao Takahata
- The Wind Rises : Hayao Miyazaki
- From Up on Poppy Hill : Gorō Miyazaki
- Arrietty : Hiromasa Yonebayashi
- Ponyo : Hayao Miyazaki
- Tales from Earthsea : Gorō Miyazaki
- Howl's Moving Castle : Hayao Miyazaki
- The Cat Returns : Hiroyuki Morita
- Spirited Away : Hayao Miyazaki
- My Neighbors the Yamadas : Isao Takahata
- Princess Mononoke : Hayao Miyazaki
- Whisper of the Heart : Yoshifumi Kondō
- Pom Poko : Isao Takahata
- Porco Rosso : Hayao Miyazaki
- Only Yesterday : Isao Takahata
- Kiki's Delivery Service : Hayao Miyazaki
- My Neighbor Totoro : Hayao Miyazaki
- Grave of the Fireflies : Isao Takahata
- Castle in the Sky : Hayao Miyazaki
Directors
- Michaël Dudok de Wit
- Yoshifumi Kondō
- Gorō Miyazaki
- Hayao Miyazaki
- Hiroyuki Morita
- Isao Takahata
- Hiromasa Yonebayashi
H. Miyazakis's Films
- The Red Turtle : Michaël Dudok de Wit
- When Marnie Was There : Hiromasa Yonebayashi
- The Tale of the Princess Kaguya : Isao Takahata
- The Wind Rises : Hayao Miyazaki
- From Up on Poppy Hill : Gorō Miyazaki
- Arrietty : Hiromasa Yonebayashi
- Ponyo : Hayao Miyazaki
- Tales from Earthsea : Gorō Miyazaki
- Howl's Moving Castle : Hayao Miyazaki
- The Cat Returns : Hiroyuki Morita
- Spirited Away : Hayao Miyazaki
- My Neighbors the Yamadas : Isao Takahata
- Princess Mononoke : Hayao Miyazaki
- Whisper of the Heart : Yoshifumi Kondō
- Pom Poko : Isao Takahata
- Porco Rosso : Hayao Miyazaki
- Only Yesterday : Isao Takahata
- Kiki's Delivery Service : Hayao Miyazaki
- My Neighbor Totoro : Hayao Miyazaki
- Grave of the Fireflies : Isao Takahata
- Castle in the Sky : Hayao Miyazaki
Directors
- Michaël Dudok de Wit
- Yoshifumi Kondō
- Gorō Miyazaki
- Hayao Miyazaki
- Hiroyuki Morita
- Isao Takahata
- Hiromasa Yonebayashi
Films By Director
- Michaël Dudok de Wit
- The Red Turtle
- Hiromasa Yonebayashi
- When Marnie Was There
- Arrietty
- Gorō Miyazaki
- From Up on Poppy Hill
- Tales from Earthsea
- Hiroyuki Morita
- The Cat Returns
- Yoshifumi Kondō
- Whisper of the Heart
- Isao Takahata
- The Tale of the Princess Kaguya
- My Neighbors the Yamadas
- Pom Poko
- Only Yesterday
- Grave of the Fireflies
- Hayao Miyazaki
- The Wind Rises
- Ponyo
- Howl's Moving Castle
- Spirited Away
- Princess Mononoke
- Porco Rosso
- Kiki's Delivery Service
- My Neighbor Totoro
- Castle in the Sky
async function getFilms() {
try {
const url = 'https://ghibliapi.herokuapp.com/films';
const filmsResponse = await fetch(`${url}`);
const films = await filmsResponse.json();
//Hayao Miyazaki
films.forEach(({ director, title }) =>
document
.querySelector("#filmsBy")
.insertAdjacentHTML('afterbegin', `<li ${"Hayao Miyazaki" == director ? 'class="selected"' : ""}> ${title} : ${director} </li>`))
//find directors
const directors = films.map(({ director }) => director);
[... new Set(directors)]
.sort((a, b) => {
if (a.split(" ")[1] > b.split(" ")[1])
return -1;
else
return 1;
})
.forEach((director) => {
document
.querySelector("#directors")
.insertAdjacentHTML('afterbegin', `<li> ${director} </li>`)
})
//directors's films
const directorsFilms = films.reduce((a, { director, title }) => {
if (!a[director]) a[director] = [];
a[director].push(title);
return a;
}, []);
//views
Object.entries(directorsFilms).forEach(([director, films]) => {
const tempLi = document.createElement('li')
, tempUl = document.createElement('ul');
films.forEach((film) => tempUl.insertAdjacentHTML('afterbegin', `<li> ${film} </li>`))
tempLi.insertAdjacentElement('beforeend', tempUl)
.insertAdjacentText('beforebegin', `${director}`)
document
.querySelector("#directorsfilmsList")
.insertAdjacentElement('afterbegin', tempLi)
})
} catch (error) {
console.log(error);
}
}
getFilms();