커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
2주차 수업과 숙제 관련 질문입니다.
undefined주차
북마크
김*슬
댓글
2
추천
0
조회수
8
조회수
8
답변 완료

따릉이 예시로 문제를 풀 때 fetch 구문은

fetch("http://spartacodingclub.shop/sparta_api/seoulbike").then(res => res.json()).then(data => {
                let rows = data['getStationList']['row']
                $('#names-q1').empty()
                rows.forEach((a) => {
                    let name = a['stationName']
                    let rack = a['rackTotCnt']
                    let bike = a['parkingBikeTotCnt']


                    let temp_html = ``


                    if (bike <5 ) {
                        temp_html = `<tr class='red'>
                                        <td>${name}</td>
                                        <td>${rack}</td>
                                        <td>${bike}</td>
                                    </tr>`
                    } else {
                        temp_html = `<tr>
                                        <td>${name}</td>
                                        <td>${rack}</td>
                                        <td>${bike}</td>
                                    </tr>`
                    }
                    
                    $('#names-q1').append(temp_html)


                })
            })


이고, 숙제 부분은

fetch("http://spartacodingclub.shop/sparta_api/weather/seoul").then(res => res.json()).then(data => {
                let number = data['temp']
                $('#temp').text(number)
            })

이잖아요


이때 각

$('#names-q1').append(temp_html)

$('#temp').text(number)

만 놓고 보면

왜 append 대신 text가 들어간 것인지 잘 이해가 가지 않아요..


따릉이는 temp_html로 name,rack,bike를 묶어서 append(temp_html)로 표기한 거고

숙제에선 그냥 온도만 표기 하기 때문에 temp_html대신 number를 넣은 것까진 모호하게 이해가 갑니다.


1) 그럼 append 대신 text가 들어간 이유는 단순히 숫자라서 text가 들어간 것인가요?


2) 따릉이 부분에서

 let rows = data['getStationList']['row']

의 rows<<의 s는 표시할 데이터가 여러개라 rows인가요..?




2주차부터 갑자기 어려워져서 질문 자체도 제가 맞는 질문을 하는 건지 잘 모르겠어요.. ^^;;..

취소
 공유
취소
댓글 0
댓글 알림
나의얼굴