第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何把json數(shù)據(jù)加載到j(luò)s變量中?

如何把json數(shù)據(jù)加載到j(luò)s變量中?

素胚勾勒不出你 2019-05-22 20:41:18
實現(xiàn)滾動加載*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}li,ul{list-style:none;}.container{width:980px;height:600px;margin:0auto;overflow:auto;}.news__item{height:80px;margin-bottom:20px;border:1pxsolid#eee;}1、helloworld2、helloworld3、helloworld4、helloworld5、helloworld6、helloworldvarwrapper=document.querySelector('.container')varcontainer=document.querySelector('.news')wrapper.addEventListener('scroll',function(){varscrollTop=wrapper.scrollTop;if(scrollTop+wrapper.clientHeight>=container.clientHeight){//觸發(fā)加載數(shù)據(jù)loadMore();}});//渲染數(shù)據(jù)functionloadMore(){varcontent='這是數(shù)據(jù)';varnode=document.getElementById('news');//向節(jié)點內(nèi)插入新生成的數(shù)據(jù)varoldContent=node.innerHTML;node.innerHTML=oldContent+content;}上面代碼是一個下拉自動加載數(shù)據(jù)的,主要是加載varcontent='這里面的數(shù)據(jù)';但是我總不能把數(shù)據(jù)寫死吧,我有個data.json的數(shù)據(jù)文件我想把data.json的數(shù)據(jù)加載在varcontent='';中,并且每向下拉一下,就加載一個id的數(shù)據(jù)data.json[{"id":"001","title":"百度","url":"http://www.baidu.com"},{"id":"002","title":"阿里","url":"www.alibaba.com"},{"id":"003","title":"騰訊","url":"www.qq.com"}]這個代碼應(yīng)該如何完善?
查看完整描述

2 回答

?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊

ajax正解,比如用jQuery就可以這:
//假設(shè)你的data.json就在網(wǎng)站test目錄下:
$.getJSON("/test/data.json",function(data){
content=data;
//然后繼續(xù)用content就行了
})
//注意不要在這里用content,要在上面那個function里面(因為$.getJSON是異步的)
                            
查看完整回答
反對 回復(fù) 2019-05-22
?
揚帆大魚

TA貢獻1799條經(jīng)驗 獲得超9個贊

定義一個id值,每次下拉的時候執(zhí)行json數(shù)據(jù)循環(huán),找出id+1對應(yīng)的數(shù)據(jù)就可以了啊!vardata=json中的數(shù)據(jù),然后foreach一下就行。
                            
查看完整回答
反對 回復(fù) 2019-05-22
  • 2 回答
  • 0 關(guān)注
  • 397 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號