var data = [{
"landpin": "015-08-0011-000-01",
"landarp": "015-08-0011-000-01",
"landtin": "342-432-423-000",
"landfirstname": "John",
"landmiddlename": "James",
"landlastname": "Jones",
"landsuffix": "",
"landqtr": "1st",
"landyear": "2014",
"landkindcode": "1",
"landkindname": "Land",
"landkindsysid": "1",
"landsurvey": "PSD-413-621-513",
"landtct_cloa": "OCT-351-561-623",
"landarea": "1000",
"landclassification": "Residential",
"landclasscode": "R",
"landprovince": "Province",
"landmunicipality": "Municipality",
"landbarangay": "District",
"landlot": "3",
"landblock": "6",
"LandAddress": [{
"landownercontactflag": "0",
"landownerprovince": "Province",
"landownermunicipality": "Municipality",
"landownerbarangay": "District 2",
"landownerstreet": "23",
"landownerzipcode": "4311"
}, {
"landownercontactflag": "1",
"landownerprovince": "Province 2",
"landownermunicipality": "Municipality 3",
"landownerbarangay": "District 3",
"landownerstreet": "34",
"landownerzipcode": "1218"
}],
"bldgpin": "015-08-0011-000-01-1001",
"bldgtin": "342-432-423-000",
"bldgfirstname": "John",
"bldgmiddlename": "James",
"bldglastname": "Jones",
"bldgsuffix": "",
"bldgqtr": "1st",
"bldgyear": "2013",
"bldgkindcode": "10",
"bldgkindname": "Buildings and Other Structures",
"bldgkindsysid": "10",
"BuildingAddress": [{
"bldgownercontactflag": "0",
"bldgownerprovince": "Province",
"bldgownermunicipality": "Municipality",
"bldgownerbarangay": "District 2",
"bldgownerstreet": "23",
"bldgownerzipcode": "4311"
}, {
"bldgownercontactflag": "1",
"bldgownerprovince": "Province 2",
"bldgownermunicipality": "Municipality 3",
"bldgownerbarangay": "District 3",
"bldgownerstreet": "34",
"bldgownerzipcode": "1218"
}],
"mchnspin": "015-08-0011-000-01-2001",
"mchnstin": "342-432-423-000",
"mchnsfirstname": "John",
"mchnsmiddlename": "James",
"mchnslastname": "Jones",
"mchnssuffix": "",
"mchnsqtr": "1st",
"mchnsyear": "2013",
"mchnskindcode": "3",
"mchnskindname": "Machinery",
"mchnskindsysid": "3",
"otherspin": "015-08-0011-000-01",
"otherstin": "342-432-423-000",
"otherfirstname": "John",
"othermiddlename": "James",
"otherlastname": "Jones",
"othersuffix": "",
"othersqtr": "1st",
"othersyear": "2013",
"otherskindcode": "11",
"otherskindname": "Other Improvements",
"otherskindsysid": "11"
}, {
"landpin": "015-08-0011-000-01",
"landarp": "015-08-0011-000-01",
"landtin": "342-432-423-000",
"landfirstname": "John",
"landmiddlename": "James",
"landlastname": "Jones",
"landsuffix": "",
"landqtr": "1st",
"landyear": "2014",
"landkindcode": "1",
"landkindname": "Land",
"landkindsysid": "1",
"landsurvey": "PSD-413-621-513",
"landtct_cloa": "OCT-351-561-623",
"landarea": "1000",
"landclassification": "Residential",
"landclasscode": "R",
"landprovince": "Province",
"landmunicipality": "Municipality",
"landbarangay": "District",
"landlot": "3",
"landblock": "6",
"LandAddress": [{
"landownercontactflag": "0",
"landownerprovince": "Province",
"landownermunicipality": "Municipality",
"landownerbarangay": "District 2",
"landownerstreet": "23",
"landownerzipcode": "4311"
}, {
"landownercontactflag": "1",
"landownerprovince": "Province 2",
"landownermunicipality": "Municipality 3",
"landownerbarangay": "District 3",
"landownerstreet": "34",
"landownerzipcode": "1218"
}],
"bldgpin": "015-08-0011-000-01-1001",
"bldgtin": "342-432-423-000",
"bldgfirstname": "John",
"bldgmiddlename": "James",
"bldglastname": "Jones",
"bldgsuffix": "",
"bldgqtr": "1st",
"bldgyear": "2014",
"bldgkindcode": "10",
"bldgkindname": "Buildings and Other Structures",
"bldgkindsysid": "10",
"BuildingAddress": [{
"bldgownercontactflag": "0",
"bldgownerprovince": "Province",
"bldgownermunicipality": "Municipality",
"bldgownerbarangay": "District 2",
"bldgownerstreet": "23",
"bldgownerzipcode": "4311"
}, {
"bldgownercontactflag": "1",
"bldgownerprovince": "Province 2",
"bldgownermunicipality": "Municipality 3",
"bldgownerbarangay": "District 3",
"bldgownerstreet": "34",
"bldgownerzipcode": "1218"
}],
"mchnspin": "015-08-0011-000-01-2001",
"mchnstin": "342-432-423-000",
"mchnsfirstname": "John",
"mchnsmiddlename": "James",
"mchnslastname": "Jones",
"mchnssuffix": "",
"mchnsqtr": "1st",
"mchnsyear": "2013",
"mchnskindcode": "3",
"mchnskindname": "Machinery",
"mchnskindsysid": "3",
"otherspin": "015-08-0011-000-01",
"otherstin": "342-432-423-000",
"otherfirstname": "John",
"othermiddlename": "James",
"otherlastname": "Jones",
"othersuffix": "",
"othersqtr": "1st",
"othersyear": "2013",
"otherskindcode": "11",
"otherskindname": "Other Improvements",
"otherskindsysid": "11"
}]
var arr2 = [];
var landtr = $('<tr><tr/>');
var bldgtr = $('<tr><tr/>');
var td;
var tr;
for (var i = 0; i < data.length; i++) {
tr = $('<tr/>');
td = $('<td/>');
var land = data[i].landpin + data[i].landyear + data[i].landkindsysid;
var bldg = data[i].bldgpin + data[i].bldgyear + data[i].bldkindsysid;
var mchns = data[i].mchnspin + data[i].mchnsyear + data[i].mchnskindsysid;
var others = data[i].otherspin + data[i].othersyear + data[i].otherskindsysid;
if ($.inArray(land, arr2) == -1) { //check if id value not exits than add it
arr2.push(land);
if (data[i].landpin) {
var landaddress = data[i].LandAddress;
landtr.append("<td id=''>" + data[i].landarp + "</td>");
landtr.append("<td id=''>" + data[i].landarp + "</td>");
landtr.append("<td id=''>" + data[i].landpin + "</td>");
landtr.append("<td id=''>" + (data[i].landlot ? "Lot " + data[i].landlot : "") + "/" + (data[i].landblock ? "Block " + data[i].landblock : "") + "</td>");
landtr.append("<td id=''>" + data[i].landfirstname + " " + data[i].landmiddlename + " " + data[i].landlastname + ", " + data[i].landsuffix + "</td>");
for (var land = 0; land < landaddress.length; land++) {
var contactaddress;
var homeaddress;
landtr.append("<td id=''>" + landaddress[land].landownercontactflag === "1" ? (contactaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet) : (homeaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet) + "</td>");
}
landtr.append("<td id=''>" + data[i].landkindname + "</td>");
landtr.append("<td id=''>" + data[i].landclassification + "</td>");
landtr.append("<td id=''>" + data[i].landfinalvalue + "</td>");
landtr.append("<td id=''></td>");
landtr.append("<td id=''>" + data[i].landyear + "</td>");
landtr.append("<td id=''></td>");
}
$("#searchresult").append(landtr);
}
if ($.inArray(bldg, arr2) == -1) { //check if id value not exits than add it
arr2.push(bldg);
if (data[i].bldgpin) {
var bldgaddress = data[i].BuildingAddress;
bldgtr.append("<td id=''>" + data[i].bldgarp + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgarp + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgpin + "</td>");
bldgtr.append("<td id=''>" + (data[i].bldglot ? "Lot " + data[i].bldglot : "") + "/" + (data[i].bldgblock ? "Block " + data[i].bldgblock : "") + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgfirstname + " " + data[i].bldgmiddlename + " " + data[i].bldglastname + ", " + data[i].bldgsuffix + "</td>");
for (var bldg = 0; bldg < bldgaddress.length; bldg++) {
var contactaddress;
var homeaddress;
bldgtr.append("<td id=''>" + bldgaddress[bldg].bldgownercontactflag === "1" ? (contactaddress = bldgaddress[bldg].bldgownerprovince + " " + bldgaddress[bldg].bldgownermunicipality + " " + bldgaddress[bldg].bldgownerbarangay + ", " + bldgaddress[bldg].bldgownerstreet) : (homeaddress = bldgaddress[bldg].bldgownerprovince + " " + bldgaddress[bldg].bldgownermunicipality + " " + bldgaddress[bldg].bldgownerbarangay + ", " + bldgaddress[bldg].bldgownerstreet) + "</td>");
}
bldgtr.append("<td id=''>" + data[i].bldgkindname + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgclassification + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgfinalvalue + "</td>");
bldgtr.append("<td id=''></td>");
bldgtr.append("<td id=''>" + data[i].bldgyear + "</td>");
bldgtr.append("<td id=''></td>");
}
$("#searchresult").append(bldgtr);
}
// if ($.inArray(mchns, arr2) == -1) { //check if id value not exits than add it
// arr2.push(mchns);
// if(data[i].mchnspin){
// $("#searchresult").append("<tr><td id=''>" + data[i].mchnspin + "</td>"
// +"<td id=''>" + data[i].mchnstin + "</td>"
// +"<td data-table='machines'>" + data[i].mchnskindname + "</td>"
// +"<td id=''>" + data[i].mchnsfirstname + " " + data[i].mchnsmiddlename + " " + data[i].mchnslastname + ", " + data[i].mchnssuffix + "</td>"
// +"<td id=''>" + data[i].mchnsqtr + "</td>"
// +"<td id=''>" + data[i].mchnsyear + "</td>"
// +"<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].mchnspin + " href='#' >View Details</a>" + "</td></tr>");
// tr.append("<td id=''>" + data[i].mchnstin + "</td>");
// tr.append("<td id=''>" + data[i].mchnsfirstname + " " + data[i].mchnsmiddlename + " " + data[i].mchnslastname + ", " + data[i].mchnssuffix + "</td>");
// tr.append("<td id=''>" + data[i].mchnsqtr + "</td>");
// tr.append("<td id=''>" + data[i].mchnsyear + "</td>");
// }
// }
// if ($.inArray(others, arr2) == -1) { //check if id value not exits than add it
// arr2.push(others);
// if(data[i].otherspin){
// $("#searchresult").append("<tr><td id=''>" + data[i].otherspin + "</td>"
// +"<td id=''>" + data[i].otherstin + "</td>"
// +"<td data-table='otherimprov'>" + data[i].otherskindname + "</td>"
// +"<td id=''>" + data[i].otherfirstname + " " + data[i].othermiddlename + " " + data[i].otherlastname + ", " + data[i].othersuffix + "</td>"
// +"<td id=''>" + data[i].othersqtr + "</td>"
// +"<td id=''>" + data[i].othersyear + "</td>"
// +"<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].otherspin + " href='#' >View Details</a>" + "</td></tr>");
// tr.append("<td id=''>" + data[i].otherstin + "</td>");
// tr.append("<td id=''>" + data[i].othersfirstname + " " + data[i].othersmiddlename + " " + data[i].otherslastname + ", " + data[i].otherssuffix + "</td>");
// tr.append("<td id=''>" + data[i].othersqtr + "</td>");
// tr.append("<td id=''>" + data[i].othersyear + "</td>");
// }
// }
//tr.append("<td id=''>" + data[i].reg_year + "</td>");
//tr.append("<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].pin + " href='#' >View Details</a>" + "</td>");
//$("#searchresult").append(tr);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table width="100%" border="1" id="searchresult">
<tr align="center">
<td>ARPN</td>
<td>T.D.
<br>NO.</td>
<td>PIN</td>
<td>LOT/
<br>BLOCK
<br>NO.</td>
<td>PROPERTY
<br>OWNER</td>
<td>ADDRESS OF
<br>PROPERTY
<br>OWNER</td>
<td>K
<br>I
<br>N
<br>D</td>
<td>CLASSIFI-
<br>CATION</td>
<td>ASSESSED
<br>VALUE</td>
<td>LEGAL
<br>BASIS</td>
<td>EFFECTIVITY</td>
<td>REMARKS</td>
</tr>
</table>
&#13;
我想根据引脚在表中添加新行。我在我的例子中附加了4种类型我只添加了2.当添加土地时,表格是可以的,当我添加构建表变得扭曲。它不会添加新行,而是继续前一行,我特意将var放在值为$('<tr><tr/>')
的情况下,并将数据附加到该变量中,如variable.append("<td id=''>" + data[i].value+ "</td>")
,但为什么表格会失真
答案 0 :(得分:1)
我可以在您的代码中看到两个错误:
landtr
和ldgtr
,然后您只创建了一行,并将所有td
标记附加到这两行中。true ? x : y
),您没有使用括号来分隔它们,这导致了一些逻辑错误。请查看下面修改后的代码,修复上述两个错误:
var data = [{
"landpin": "015-08-0011-000-01",
"landarp": "015-08-0011-000-01",
"landtin": "342-432-423-000",
"landfirstname": "John",
"landmiddlename": "James",
"landlastname": "Jones",
"landsuffix": "",
"landqtr": "1st",
"landyear": "2014",
"landkindcode": "1",
"landkindname": "Land",
"landkindsysid": "1",
"landsurvey": "PSD-413-621-513",
"landtct_cloa": "OCT-351-561-623",
"landarea": "1000",
"landclassification": "Residential",
"landclasscode": "R",
"landprovince": "Province",
"landmunicipality": "Municipality",
"landbarangay": "District",
"landlot": "3",
"landblock": "6",
"LandAddress": [{
"landownercontactflag": "0",
"landownerprovince": "Province",
"landownermunicipality": "Municipality",
"landownerbarangay": "District 2",
"landownerstreet": "23",
"landownerzipcode": "4311"
}, {
"landownercontactflag": "1",
"landownerprovince": "Province 2",
"landownermunicipality": "Municipality 3",
"landownerbarangay": "District 3",
"landownerstreet": "34",
"landownerzipcode": "1218"
}],
"bldgpin": "015-08-0011-000-01-1001",
"bldgtin": "342-432-423-000",
"bldgfirstname": "John",
"bldgmiddlename": "James",
"bldglastname": "Jones",
"bldgsuffix": "",
"bldgqtr": "1st",
"bldgyear": "2013",
"bldgkindcode": "10",
"bldgkindname": "Buildings and Other Structures",
"bldgkindsysid": "10",
"BuildingAddress": [{
"bldgownercontactflag": "0",
"bldgownerprovince": "Province",
"bldgownermunicipality": "Municipality",
"bldgownerbarangay": "District 2",
"bldgownerstreet": "23",
"bldgownerzipcode": "4311"
}, {
"bldgownercontactflag": "1",
"bldgownerprovince": "Province 2",
"bldgownermunicipality": "Municipality 3",
"bldgownerbarangay": "District 3",
"bldgownerstreet": "34",
"bldgownerzipcode": "1218"
}],
"mchnspin": "015-08-0011-000-01-2001",
"mchnstin": "342-432-423-000",
"mchnsfirstname": "John",
"mchnsmiddlename": "James",
"mchnslastname": "Jones",
"mchnssuffix": "",
"mchnsqtr": "1st",
"mchnsyear": "2013",
"mchnskindcode": "3",
"mchnskindname": "Machinery",
"mchnskindsysid": "3",
"otherspin": "015-08-0011-000-01",
"otherstin": "342-432-423-000",
"otherfirstname": "John",
"othermiddlename": "James",
"otherlastname": "Jones",
"othersuffix": "",
"othersqtr": "1st",
"othersyear": "2013",
"otherskindcode": "11",
"otherskindname": "Other Improvements",
"otherskindsysid": "11"
}, {
"landpin": "015-08-0011-000-01",
"landarp": "015-08-0011-000-01",
"landtin": "342-432-423-000",
"landfirstname": "John",
"landmiddlename": "James",
"landlastname": "Jones",
"landsuffix": "",
"landqtr": "1st",
"landyear": "2014",
"landkindcode": "1",
"landkindname": "Land",
"landkindsysid": "1",
"landsurvey": "PSD-413-621-513",
"landtct_cloa": "OCT-351-561-623",
"landarea": "1000",
"landclassification": "Residential",
"landclasscode": "R",
"landprovince": "Province",
"landmunicipality": "Municipality",
"landbarangay": "District",
"landlot": "3",
"landblock": "6",
"LandAddress": [{
"landownercontactflag": "0",
"landownerprovince": "Province",
"landownermunicipality": "Municipality",
"landownerbarangay": "District 2",
"landownerstreet": "23",
"landownerzipcode": "4311"
}, {
"landownercontactflag": "1",
"landownerprovince": "Province 2",
"landownermunicipality": "Municipality 3",
"landownerbarangay": "District 3",
"landownerstreet": "34",
"landownerzipcode": "1218"
}],
"bldgpin": "015-08-0011-000-01-1001",
"bldgtin": "342-432-423-000",
"bldgfirstname": "John",
"bldgmiddlename": "James",
"bldglastname": "Jones",
"bldgsuffix": "",
"bldgqtr": "1st",
"bldgyear": "2014",
"bldgkindcode": "10",
"bldgkindname": "Buildings and Other Structures",
"bldgkindsysid": "10",
"BuildingAddress": [{
"bldgownercontactflag": "0",
"bldgownerprovince": "Province",
"bldgownermunicipality": "Municipality",
"bldgownerbarangay": "District 2",
"bldgownerstreet": "23",
"bldgownerzipcode": "4311"
}, {
"bldgownercontactflag": "1",
"bldgownerprovince": "Province 2",
"bldgownermunicipality": "Municipality 3",
"bldgownerbarangay": "District 3",
"bldgownerstreet": "34",
"bldgownerzipcode": "1218"
}],
"mchnspin": "015-08-0011-000-01-2001",
"mchnstin": "342-432-423-000",
"mchnsfirstname": "John",
"mchnsmiddlename": "James",
"mchnslastname": "Jones",
"mchnssuffix": "",
"mchnsqtr": "1st",
"mchnsyear": "2013",
"mchnskindcode": "3",
"mchnskindname": "Machinery",
"mchnskindsysid": "3",
"otherspin": "015-08-0011-000-01",
"otherstin": "342-432-423-000",
"otherfirstname": "John",
"othermiddlename": "James",
"otherlastname": "Jones",
"othersuffix": "",
"othersqtr": "1st",
"othersyear": "2013",
"otherskindcode": "11",
"otherskindname": "Other Improvements",
"otherskindsysid": "11"
}]
var arr2 = [];
var td;
var tr;
for (var i = 0; i < data.length; i++) {
var landtr = $('<tr><tr/>');
var bldgtr = $('<tr><tr/>');
tr = $('<tr/>');
td = $('<td/>');
var land = data[i].landpin + data[i].landyear + data[i].landkindsysid;
var bldg = data[i].bldgpin + data[i].bldgyear + data[i].bldkindsysid;
var mchns = data[i].mchnspin + data[i].mchnsyear + data[i].mchnskindsysid;
var others = data[i].otherspin + data[i].othersyear + data[i].otherskindsysid;
if ($.inArray(land, arr2) == -1) { //check if id value not exits than add it
arr2.push(land);
if (data[i].landpin) {
var landaddress = data[i].LandAddress;
landtr.append("<td id=''>" + data[i].landarp + "</td>");
landtr.append("<td id=''>" + data[i].landarp + "</td>");
landtr.append("<td id=''>" + data[i].landpin + "</td>");
landtr.append("<td id=''>" + (data[i].landlot ? "Lot " + data[i].landlot : "") + "/" + (data[i].landblock ? "Block " + data[i].landblock : "") + "</td>");
landtr.append("<td id=''>" + data[i].landfirstname + " " + data[i].landmiddlename + " " + data[i].landlastname + ", " + data[i].landsuffix + "</td>");
var td_content = [];
for (var land = 0; land < landaddress.length; land++) {
var contactaddress;
var homeaddress;
td_content.push((landaddress[land].landownercontactflag === "1" ? (contactaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet) : (homeaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet)));
}
landtr.append("<td id=''>" + td_content.join(' / ') + "</td>");
landtr.append("<td id=''>" + data[i].landkindname + "</td>");
landtr.append("<td id=''>" + data[i].landclassification + "</td>");
landtr.append("<td id=''>" + data[i].landfinalvalue + "</td>");
landtr.append("<td id=''></td>");
landtr.append("<td id=''>" + data[i].landyear + "</td>");
landtr.append("<td id=''></td>");
}
$("#searchresult").append(landtr);
}
if ($.inArray(bldg, arr2) == -1) { //check if id value not exits than add it
arr2.push(bldg);
if (data[i].bldgpin) {
var bldgaddress = data[i].BuildingAddress;
bldgtr.append("<td id=''>" + data[i].bldgarp + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgarp + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgpin + "</td>");
bldgtr.append("<td id=''>" + (data[i].bldglot ? "Lot " + data[i].bldglot : "") + "/" + (data[i].bldgblock ? "Block " + data[i].bldgblock : "") + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgfirstname + " " + data[i].bldgmiddlename + " " + data[i].bldglastname + ", " + data[i].bldgsuffix + "</td>");
var td_content = [];
for (var bldg = 0; bldg < bldgaddress.length; bldg++) {
var contactaddress;
var homeaddress;
td_content.push((bldgaddress[bldg].bldgownercontactflag === "1" ? (contactaddress = bldgaddress[bldg].bldgownerprovince + " " + bldgaddress[bldg].bldgownermunicipality + " " + bldgaddress[bldg].bldgownerbarangay + ", " + bldgaddress[bldg].bldgownerstreet) : (homeaddress = bldgaddress[bldg].bldgownerprovince + " " + bldgaddress[bldg].bldgownermunicipality + " " + bldgaddress[bldg].bldgownerbarangay + ", " + bldgaddress[bldg].bldgownerstreet)));
}
bldgtr.append("<td id=''>" + td_content.join(' / ') + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgkindname + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgclassification + "</td>");
bldgtr.append("<td id=''>" + data[i].bldgfinalvalue + "</td>");
bldgtr.append("<td id=''></td>");
bldgtr.append("<td id=''>" + data[i].bldgyear + "</td>");
bldgtr.append("<td id=''></td>");
}
$("#searchresult").append(bldgtr);
}
// if ($.inArray(mchns, arr2) == -1) { //check if id value not exits than add it
// arr2.push(mchns);
// if(data[i].mchnspin){
// $("#searchresult").append("<tr><td id=''>" + data[i].mchnspin + "</td>"
// +"<td id=''>" + data[i].mchnstin + "</td>"
// +"<td data-table='machines'>" + data[i].mchnskindname + "</td>"
// +"<td id=''>" + data[i].mchnsfirstname + " " + data[i].mchnsmiddlename + " " + data[i].mchnslastname + ", " + data[i].mchnssuffix + "</td>"
// +"<td id=''>" + data[i].mchnsqtr + "</td>"
// +"<td id=''>" + data[i].mchnsyear + "</td>"
// +"<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].mchnspin + " href='#' >View Details</a>" + "</td></tr>");
// tr.append("<td id=''>" + data[i].mchnstin + "</td>");
// tr.append("<td id=''>" + data[i].mchnsfirstname + " " + data[i].mchnsmiddlename + " " + data[i].mchnslastname + ", " + data[i].mchnssuffix + "</td>");
// tr.append("<td id=''>" + data[i].mchnsqtr + "</td>");
// tr.append("<td id=''>" + data[i].mchnsyear + "</td>");
// }
// }
// if ($.inArray(others, arr2) == -1) { //check if id value not exits than add it
// arr2.push(others);
// if(data[i].otherspin){
// $("#searchresult").append("<tr><td id=''>" + data[i].otherspin + "</td>"
// +"<td id=''>" + data[i].otherstin + "</td>"
// +"<td data-table='otherimprov'>" + data[i].otherskindname + "</td>"
// +"<td id=''>" + data[i].otherfirstname + " " + data[i].othermiddlename + " " + data[i].otherlastname + ", " + data[i].othersuffix + "</td>"
// +"<td id=''>" + data[i].othersqtr + "</td>"
// +"<td id=''>" + data[i].othersyear + "</td>"
// +"<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].otherspin + " href='#' >View Details</a>" + "</td></tr>");
// tr.append("<td id=''>" + data[i].otherstin + "</td>");
// tr.append("<td id=''>" + data[i].othersfirstname + " " + data[i].othersmiddlename + " " + data[i].otherslastname + ", " + data[i].otherssuffix + "</td>");
// tr.append("<td id=''>" + data[i].othersqtr + "</td>");
// tr.append("<td id=''>" + data[i].othersyear + "</td>");
// }
// }
//tr.append("<td id=''>" + data[i].reg_year + "</td>");
//tr.append("<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\" id=" + data[i].pin + " href='#' >View Details</a>" + "</td>");
//$("#searchresult").append(tr);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table width="100%" border="1" id="searchresult">
<tr align="center">
<td>ARPN</td>
<td>T.D.
<br>NO.</td>
<td>PIN</td>
<td>LOT/
<br>BLOCK
<br>NO.</td>
<td>PROPERTY
<br>OWNER</td>
<td>ADDRESS OF
<br>PROPERTY
<br>OWNER</td>
<td>K
<br>I
<br>N
<br>D</td>
<td>CLASSIFI-
<br>CATION</td>
<td>ASSESSED
<br>VALUE</td>
<td>LEGAL
<br>BASIS</td>
<td>EFFECTIVITY</td>
<td>REMARKS</td>
</tr>
</table>
&#13;
<强>更新强>
如果要在一个td
中显示所有地址,则必须创建一个辅助变量来连接所有地址,然后将连接附加到单个td
。
请查看上面的更新示例。
答案 1 :(得分:0)
您需要克隆tr
个变量,否则您将继续追加到相同的tr
元素。首先,将变量更改为:
var land_tr = $('<tr><tr/>');
var bldg_tr = $('<tr><tr/>');
然后,添加一个克隆行,如下所示:
for (var i = 0; i < data.length; i++) {
var landtr = land_tr.clone(); // <<<<--- ADD THIS
var bldgtr = bldg_tr.clone(); // <<<<--- ADD THIS
tr = $('<tr/>');
td = $('<td/>');
var land = data[i].landpin + data[i].landyear + data[i].landkindsysid;
请注意:即使您的浏览器没有投诉,添加tr
元素的正确元素仍然是tbody
,thead
或{{ 1}}元素。