json 날짜별로 출력

json 날짜별로 출력

QA

json 날짜별로 출력

본문

API를 통해 리스트를 뿌려주는데 날짜별로 정렬하고자합니다 새로고침때마다 랜덤으로 출력되고 있습니다

날짜별 정렬 코드 봐주세요~

978270809_1629874731.441.png


                        fetch(fourthUrl, options)
                            .then(async res => await res.json())
                            .then(async res => {
                                obj_payouts = await res.data;
                                const sortedPayouts = obj_payouts.sort((a, b) => b.paidOn - a.paidOn);
                                for (let i = 0; i < sortedPayouts.length; i++) {
                                    totalEth += parseFloat((sortedPayouts[i]["amount"] / 100) / 10000000000000000);
                                    console.log(totalEth);
                                    const url ='https://api.upbit.com/v1/candles/minutes/1?market=KRW-ETH&count=1&to=' + new Date(sortedPayouts[i]['paidOn'] * 1000).toISOString().replace(".000", "");
                                    const newOption = {
                                        method: 'GET',
                                        headers: {
                                            Accept: 'application/json'
                                        }
                                    }
                                    //sleep(100);
                                    fetch(url, newOption)
                                    .then(res => res.json())
                                    .then(res => {
                                        totalPay += (res[0]["trade_price"] * parseFloat((sortedPayouts[i]["amount"] / 100) / 10000000000000000).toFixed(5));
                                        var tr = document.createElement('tr');
                                        tr.innerHTML = `
                                                    <td>${new Date(sortedPayouts[i]['paidOn'] * 1000).toISOString().split("T")[0] + " " + new Date(sortedPayouts[i]['paidOn'] * 1000).toISOString().split("T")[1].replace(".000Z", "")}</td>
                                                    <td style="line-height: 20px;"><span class="hash">${sortedPayouts[i]['start']}</span><a href="https://www.etherchain.org/block/${sortedPayouts[i]['start']}" style="margin-left:5px; border:1px solid #ddd; padding:0 3px; color:#bbb; float:right;" target="_blank"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></td>
                                                    <td><img src="http://golden-mining.com/app/img/upbit.png" style='width: 22px; margin-right: 5px; vertical-align: middle;'>${(Math.round((res[0]["trade_price"] * parseFloat((sortedPayouts[i]["amount"] / 100) / 10000000000000000).toFixed(5)))).toLocaleString()}원</td>
                                                    <td><img src="http://golden-mining.com/app/img/eth.png" style='width: 22px; vertical-align: middle;'>${parseFloat((sortedPayouts[i]["amount"] / 100) / 10000000000000000).toFixed(5)} ETH</td>
                                                    <td><span class="hash">${String(sortedPayouts[i]['txHash']).slice(0, 10)}</span> <a href="https://www.etherchain.org/tx/${sortedPayouts[i]['txHash']}" style="margin-left:5px; border:1px solid #ddd; padding:0 3px; color:#bbb; float:right;" target="_blank"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></td>
                                        `;
                                        table.appendChild(tr);
                                    });
                                }
 

이 질문에 댓글 쓰기 :

답변 1

결국은 paidOn의 비교가 제대로 되는지가 문제가 될 것 같습니다.

 

넘어오는 값이 마이너스로 비교가 되는지 > 를 사용해야 되는지...

 

다음을 참조해서 비교가 잘되는지 프린트해보세요.

 

https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value

답변을 작성하시기 전에 로그인 해주세요.
전체 184
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT