標籤 - JavaScript
2021
js循环的几种方式
js循环的几种方式
P.api.lncldglobal.com' var settings = { "method": "GET", "headers": { "X-LC-Id": 'bqz5bTsPoRoOdgSj4JP1Jon2-gzGzoHsz', "X-LC-Key": 'iuJqnSpmcjSD5lbciPxNqOBH', "Content-Type": "application/json" }, } fetch(`${serverURL}/1.1/classes/Comment?limit=6&order=-createdAt`,settings) .then(response => response.json()) .then(data => { const valineArray = data.results.map(function (e) { return { 'avatar': getIcon(e.QQAvatar, e.mail), 'content': changeContent(e.comment), 'nick': e.nick, 'url': e.url + '#' + e.objectId, 'date': e.updatedAt, } }) saveToLocal.set('valine-newest-comments', JSON.stringify(valineArray), 10/(60*24)) generateHtml(valineArray) }).catch(e => { const $dom = document.querySelector('#card-newest-comments .aside-list') $dom.textContent= "無法獲取評論,請確認相關配置是否正確" }) } const newestCommentInit = () => { if (document.querySelector('#card-newest-comments .aside-list')) { const data = saveToLocal.get('valine-newest-comments') if (data) { generateHtml(JSON.parse(data)) } else { getComment() } } } newestCommentInit() document.addEventListener('pjax:complete', newestCommentInit) })