jQuery如何遍歷Json,並且將Json中的值注入到頁面中?
jQuery如何遍歷Json,並且將Json中的值注入到頁面中?
我發你一個,大概就是這個樣子,不是注入頁面,而是在jQuery中將json數據拼裝好,然後加載到頁面中就可以了
。。
//
function initJsonFileList(){
//從json解析文件列表.
var docinfos = '[{"name":"2.jpg","storename":"1439444506913.jpg","store":"1439444506913.jpg","type":"0","operatorId":"1","operatorName":"%25E5%25BC%25A0%25E4%25B8%2589","updateFlag":0,"delFlag":"0","isNewRecord":false}]';//這一句是我現改的,你看下對不對
if(typeof(docinfos)!="undefined" && docinfos!=null && docinfos!=""){
var arr=JSON.parse(docinfos);
var html="";
$.each(arr,function(k,m){
var names = decodeURI(decodeURI(m.name));
html+="<tr name='newaddmess'><td><span class='name'>"+names+"</span>"+
"<span class='storename hiddenspan'>"+m.storename+"</span>"+
"<span class='store hiddenspan'>"+m.store+"</span>"+
"<span class='operatorId hiddenspan'>"+m.operatorId+"</span>"+
"<span class='operatorName hiddenspan'>"+m.operatorName+"</span>"+
"<span class='updateFlag hiddenspan'>"+m.updateFlag+"</span>"+
"<span class='delFlag hiddenspan'>"+m.delFlag+"</span>"+
"<span class='isNewRecord hiddenspan'>"+m.isNewRecord+"</span></td><td><input type='button' onclick=\"if(confirm('是否確認刪除?')){ $(this).parent().parent().remove();reReadJson();}\" class='btn btn-default btn-sm uploaddeletes' value='刪除' /></td></tr>";
})
$("#fileuploadstables").append(html);
}
//END解析文件列表.
}