我想在html表中插入json数据。但是我不能。我做错了什么?
在每个文本框中,我都将对象写入JSON数据:
{
invoice_no : "27745186",
line_itemID : "1",
supplier_name : "Dell",
supplier_id : "",
description : "asdsadas adsdsadasd sadasdadada dsa…",
serial_no : "",
asset_type : "",
asset_typeID : "0",
assetSubtype : "",
manufacturer : "",
// ... 79 more
}
这是我尝试过的:
var rowdt = Inv_dt.length;
jQuery("#example1 tr:last").after(generateRows(rowdt));
jQuery.each(Inv_dt, function(key, value){
jQuery("#example1 table input, select").each(function(){
this.value = value;
console.log(value);
console.log(this.name);
});
})
以及如何在regex中提取salesTaxvalue字符串?
input_[2][SALESTAXVALUE]
input_[3][SALESTAXVALUE]
select_[3][SALESTAXVALUE]
答案 0 :(得分:0)
这是我试过的,假设你的JSON数据就像
var objData = [{
invoice_no: "27745186",
line_itemID: "1",
supplier_name: "Dell",
supplier_id: "",
description: "asdsadas adsdsadasd sadasdadada dsa…",
serial_no: "",
asset_type: "",
asset_typeID: "0",
assetSubtype: "",
manufacturer: "",
}, {
invoice_no: "245186",
line_itemID: "1",
supplier_name: "HP",
supplier_id: "",
description: "sdadada dsa…",
serial_no: "",
asset_type: "",
asset_typeID: "0",
assetSubtype: "",
manufacturer: "",
}];
如果是,那么这将生成表格 $("按钮")。on('点击',功能(){
var aTable = $("#tb_Demo");
$.each(objData, function (indx) {
var col1 = objData[indx].supplier_name;
var col2 = objData[indx].invoice_no;
var col3 = objData[indx].description;
var elTROW = '<tr><td>' + col1 + '</td><td>' + col2 + '</td><td>' + col3 + '</td></tr>';
$(aTable).append(elTROW);
});
<强> DEMO 强>