@TatiNaumchuk

Отправить ajax запрос и вывести данные на страницу?

надо отправить ajax запрос https://ajax.test-danit.com/api/swapi/films и вывести все фильмы, а также список персонажей в каждом фильме (находится в свойстве characters). Как дополнить код и использовать правильно Promise.all?
const URL = 'https://ajax.test-danit.com/api/swapi/';
const root = document.querySelector('#root');

class Requests {
    constructor(url) {
        this.url = url;
    }

    getEntity(entity) {
        return fetch(this.url + `${entity}`).then(response => {
            return response.json();
        });
    }
    // getDeepEntity(entity, keyword) {
    //  return fetch(this.url + `${entity}?search=${keyword}`).then(response => {
    //      return response.json();
    //  });
    // }
}

class StarWars {
    constructor(root) {
        this.root = root;
    }

    renderEntity(data) {
        const infoEntity = document.createElement('div');

        const infoItems = data.map(({ name, episodeId, openingCrawl, characters }) => {
            const entityContainer = document.createElement('div');
            const title = document.createElement('h4');
            title.textContent = `Film name: "${name}"`;
            // const people = characters.map(elem => {
            //  console.log(elem);
            // });
            const id = document.createElement('p');
            id.textContent = `Episode: ${episodeId}`;
            id.style.fontStyle = 'italic';
            const description = document.createElement('p');
            description.textContent = `Description:${openingCrawl}`;
            entityContainer.append(title, id, description);
            return entityContainer;
        });
        infoEntity.append(...infoItems);
        this.root.append(infoEntity);
    }
}
  • Вопрос задан
  • 114 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы