欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

json數(shù)據(jù)處理及數(shù)據(jù)綁定

 更新時間:2017年01月25日 10:49:27   作者:13611606223  
本文主要介紹了json數(shù)據(jù)處理及數(shù)據(jù)綁定的相關(guān)知識。具有很好的參考價值,下面跟著小編一起來看下吧

一.json數(shù)據(jù)處理

1.json數(shù)據(jù)

{"img":"quizvault_internet_test_banner@2x.png",
"golds":"200",
"praise":"64000",
"tit":"互聯(lián)網(wǎng)給工作帶來的麻煩",
"tit_describe":"在朋友圈轉(zhuǎn)發(fā)身體被掏空,HR找你深情談話:不想干就走??纯茨阌心男┣闆r?",
"images":[{"name":"quizvault_internet_test_nor.png"},{"name":"quizvault_internet_test_nor.png"},{"name":"quizvault_internet_test_nor.png"},{"name":"quizvault_internet_test_nor.png"}],
"images_tit":[{"name":"自從大家習(xí)慣用微信工作后就要24小時standby"},{"name":"自從大家習(xí)慣用微信工作后就要24小時standby"},{"name":"自從大家習(xí)慣用微信工作后就要24小時standby"},{"name":"自從大家習(xí)慣用微信工作后就要24小時standby"}]
}

2.獲取數(shù)據(jù)

數(shù)據(jù)注入:"{{data}}"

3.數(shù)據(jù)處理:

var datas = "{{data}}";
   var data;
   srtjson(datas);
   console.log(data);
   function srtjson(datas) {
    var b = htmlDecode(datas);
    var dataObj = b.substring(1, b.length - 1);
    data = eval("(" + dataObj + ")");
    function htmlDecode(text) {
     var temp = document.createElement("div");
     temp.innerHTML = text;
     var output = temp.innerText || temp.textContent;
     temp = null;
     return output;
    }
   }

4.數(shù)據(jù)綁定

 //把json的key設(shè)為id,通過遍歷對象進(jìn)行數(shù)據(jù)綁定
  for(var p in data){ 
      $('#'+p).html(data[p]);
  };
//對數(shù)組進(jìn)行循環(huán),進(jìn)行綁定并且動態(tài)成成html
     for(var i=0;i<data.question_tit.length;i++){
     $('#J_main ul').append('<li><div class="cir">'+data.question_tit[i].name+'</div><span>'+data.question_main[i].name+'</span></li>');
                 }
//動態(tài)css進(jìn)行綁定
  $('.banner').css({
   'backgroundImage': 'url('+'images/'+ data.img+')'
  //'backgroundImage': 'url('+'{{resource}}'+ data.img+'?type=web-image'+')'
});

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論