繁体   English   中英

使用JSON动态添加表行

[英]Add table row dynamically with JSON

我很难用JSON添加新表行。

情况

目前,我正在编程拖放功能。 文件上传后,文件信息将解析为JSON并返回到“查看”页面。 我想要的是我想使用JSON文件信息动态添加新表行。

问题我应该如何用JSON格式填写双引号?

 var rowNode = table.row.add( [ "", "", "[what should i write here??]", "[what should i write here??]", "<td id=wtax_file_type></td>", "<td id=all_tax></td>", "<td id=tax_date></td>", "<button class='btn btn-xs btn-default'><i class='icon-file-pdf text-error'></i><span> 테스트.pdf</span></button>", "<a class='btn-link color-primary'>[이동]</a>" ] ).draw().node(); 

我的JS代码

 myDropzone.on("success", function(file, res) { /* removew preview when upload success*/ $(file.previewElement).remove(); console.log(res); if (res.result) { if (res.data) { if (res.data.f_idx) { $('#f_idx').text(res.data.f_idx); } if (res.data.client_name) { $('#client_name').text(res.data.client_name); } if (res.data.client_biz_no) { $('#client_biz_no').text(res.data.client_biz_no); } if (res.data.wtax_file_type) { $('#wtax_file_type').text(res.data.wtax_file_type); } if (res.data.all_tax) { $('#all_tax').text(res.data.all_tax); } if (res.data.tax_date) { $('#tax_date').text(res.data.tax_date); } } } var fileObj=JSON.parse(res); var rowNode = table.row.add( [ "", "", "[what should i write here??]", "what should i write here??]", "<td id=wtax_file_type></td>", "<td id=all_tax></td>", "<td id=tax_date></td>", "<button class='btn btn-xs btn-default'><i class='icon-file-pdf text-error'></i><span> 테스트.pdf</span></button>", "<a class='btn-link color-primary'>[이동]</a>" ] ).draw().node(); }); 

根据datatable的文档 ,可以这样完成:

table.row.add( [
        "",
        "",
        "[what should i write here??]",
        "[what should i write here??]",
        $('#wtax_file_type').text(),
        $('#all_tax').text(),
        $('#tax_date').text(),
        "<button class='btn btn-xs btn-default'><i class='icon-file-pdf text-error'></i><span> 테스트.pdf</span></button>",
        "<a class='btn-link color-primary'>[이동]</a>"
    ] ).draw( false );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM