• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    미해결

map이 안먹습니다.. ㅠㅠㅠ

22.10.06 17:35 작성 조회수 265

0

        let news = [];
        const getLatestNews = async()=>{
            let url = new URL(
            `https://api.newscatcherapi.com/v2/search?q=Apple&from='2022/10/05'&countries=CA&page_size=10`);

            let header = new Headers({
                "x-api-key": "zpAatDWQatkuDD2G4_7OSLQt344GVruaD6Rav-u8tIc"
            });

            let response = await fetch(url, { headers:header });
            let data = await response.json();
            news = data.articles;
            console.log(news);

            render()
        };
        getLatestNews();
        const render = ()=>{
            let newsHTML = "";

            newsHTML =news.map((item) => {
                return `<div class="row news">
                <div class="col-lg-4">
                    <img class="news-img-size" src="images/dish1.jpg" alt="">
                </div>
                <div class="col-lg-8">
                    <h1>헤드라인 제목</h1>
                    <p>
                        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ducimus repellendus, nobis at commodi explicabo ipsum deleniti sint quos quae tenetur, sed aspernatur consectetur quasi nostrum unde blanditiis ad quia iusto.
                    </p>
                    <div>
                        SBS * 2022-10-06
                    </div>
                </div>
            </div>`;
            });

            console.log(newsHTML);

            document.getElementById("news-board").innerHTML = newsHTML;

        };
        getLatestNews();

왜 map이 안먹는지요 정말 이것때문에 하루종일 아무것도 안되고 있습니다... ㅠㅠㅠㅠ

답변 2

·

답변을 작성해보세요.

1

한번 console.log(news)해보시겠어요?

news에 데이터가 안들어있을 확률 99프로

bbkjh님의 프로필

bbkjh

2022.10.17

감사합니다.

0

bbkjh님의 프로필

bbkjh

2022.10.06

에러 메시지입니다.

 

Uncaught Error: Bootstrap's JavaScript requires jQuery

at bootstrap.min.js:6:37

api.newscatcherapi.com/v2/latest_headlines?countries=US&topic=business&page_size=10:1 Failed to load resource: the server responded with a status of 401 ()

1006-001.html:115 undefined

1006-001.html:122 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'map')

at render (1006-001.html:122:29)

at getLatestNews (1006-001.html:117:13)

국민건강보험님의 프로필

국민건강보험

2022.10.06

안녕하세용 지나가다 혹시나 해서 댓글 남겨요! API 요청이 실패해서 발생한 문제같은데 요청값이 제대로 오는지 확인해보시면 어떨까용?