感覺這種方式很不好修改啊,萬一改代碼就會很難受
<script>
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>"+
"<td>"+
"<span>"+names+"</span>"+
"<span>"+m.storename+"</span>"+
"<span>"+m.store+"</span>"+
"<span>"+m.operatorId+"</span>"+
"<span>"+m.operatorName+"</span>"+
"<span>"+m.updateFlag+"</span>"+
"<span>"+m.delFlag+"</span>"+
"<span>"+m.isNewRecord+"</span>"+
"</td>"+
"<td>"+
"<input type='button' onclick=\"if(confirm('是否確認刪除?')){ $(this).parent().parent().remove();reReadJson();}\" value='刪除' />"+
"</td>"+
"</tr>";
})
$("#fileuploadstables").append(html);
}
//END解析文件列表.
}
</script>
可以用第三方的插件,如jqGrid,easyui的datagrid,只需要配置好columns對應你的json數據,會自動幫你生成表格數據行。不過底層的實現和你這個代碼差不多