首页 > 代码库 > jquery: json树组数据输出到表格Dom树的处理方法
jquery: json树组数据输出到表格Dom树的处理方法
项目背景
项目中需要把表格重排显示
处理方法
思路主要是用历遍Json数组把json数据一个个append到4个表格里,还要给每个单元格绑定个单击弹出自定义对话框,表格分了单双行,第一行最后还要改rowspan呵呵,程序还没优化运行正常先给客户展示先:)
1,表格数据->json数组
var keyArr = new Array(); var jsonArr = new Array(); $list.find("thead th").each(function () { keyArr.push($(this).text());//生成key }); $list.find("tbody tr").each(function () { var jsonObj = {}; $(this).find("td").each(function (n) { jsonObj[keyArr[n]] = $(this).html();// 生成value }); jsonArr.push(jsonObj); });
2,json树组数据输出到表格Dom树
$.each(jsonArr, function (entryIndex, entry) {//遍历json数组if (entry[‘CY‘] >= startYear) { switch (entry[‘Product Type‘]) { case ‘1.aaa‘: switch (entry[‘CY‘]) { case yearArr[0]: var flag = false; This.find(".itm_table:eq(0)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(0)").html() == "") { obj.find("td:eq(0)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(0)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="even"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="odd"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[1]: var flag = false; This.find(".itm_table:eq(0)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(0)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="even"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="odd"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[2]: var flag = false; This.find(".itm_table:eq(0)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(0)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="even"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[3]: var flag = false; This.find(".itm_table:eq(0)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(0)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[4]: var flag = false; This.find(".itm_table:eq(0)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(5)").html() == "") { obj.find("td:eq(5)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(5)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(0)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(0)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(0)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; default: break; } break; case ‘2.bbb‘: switch (entry[‘CY‘]) { case yearArr[0]: var flag = false; This.find(".itm_table:eq(1)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(0)").html() == "") { obj.find("td:eq(0)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(1)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="even"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="odd"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[1]: var flag = false; This.find(".itm_table:eq(1)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(1)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="even"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="odd"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[2]: var flag = false; This.find(".itm_table:eq(1)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(1)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="even"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[3]: var flag = false; This.find(".itm_table:eq(1)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(1)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[4]: var flag = false; This.find(".itm_table:eq(1)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(5)").html() == "") { obj.find("td:eq(5)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(5)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(1)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(1)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(1)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; default: break; } break; case ‘3.ccc: switch (entry[‘CY‘]) { case yearArr[0]: var flag = false; This.find(".itm_table:eq(2)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(0)").html() == "") { obj.find("td:eq(0)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(2)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="even"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="odd"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[1]: var flag = false; This.find(".itm_table:eq(2)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(2)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="even"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="odd"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[2]: var flag = false; This.find(".itm_table:eq(2)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(2)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="even"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[3]: var flag = false; This.find(".itm_table:eq(2)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(2)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[4]: var flag = false; This.find(".itm_table:eq(2)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(5)").html() == "") { obj.find("td:eq(5)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(5)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(2)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(2)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(2)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; default: break; } break; case ‘4.ddd‘: switch (entry[‘CY‘]) { case yearArr[0]: var flag = false; This.find(".itm_table:eq(3)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(0)").html() == "") { obj.find("td:eq(0)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(3)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="even"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="odd"><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(0)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[1]: var flag = false; This.find(".itm_table:eq(3)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(1)").html() == "") { obj.find("td:eq(1)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(3)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="even"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="odd"><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(1)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[2]: var flag = false; This.find(".itm_table:eq(3)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(2)").html() == "") { obj.find("td:eq(2)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(3)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="even"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(2)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[3]: var flag = false; This.find(".itm_table:eq(3)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(3)").html() == "") { obj.find("td:eq(3)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(3)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td><td></td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(3)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; case yearArr[4]: var flag = false; This.find(".itm_table:eq(3)").find("tbody>tr").each(function (n) { var obj = $(this); if (n > 0) { if (obj.find("td:eq(4)").html() == "") { obj.find("td:eq(4)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } else { if (obj.find("td:eq(5)").html() == "") { obj.find("td:eq(5)").text(entry[‘Product Name‘]); flag = true; obj.find("td:eq(5)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); return false; } } }); if (!flag) { if (This.find(".itm_table:eq(3)").find("tbody>tr:last").attr("class") == "odd") { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="even"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } else { This.find(".itm_table:eq(3)").find("tbody").append(‘<tr class="odd"><td></td><td></td><td></td><td></td><td>‘ + entry[‘Product Name‘] + ‘</td></tr>‘); This.find(".itm_table:eq(3)").find("tbody>tr:last").find("td:eq(4)").click(function () { $(this).bindTdClink(popup, entry); }).css("cursor", "pointer"); } } break; default: break; } break; default: break; } } }); This.find(".itm_table").each(function () { var self = $(this); var len = self.find("tbody>tr").length; self.find("tbody>tr:first").find("td:eq(0)").attr("rowspan", len); });
jquery: json树组数据输出到表格Dom树的处理方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。