尝试通过迭代嵌套JSON解决问题, 但它需要一些建议。 无法正确生成和标记在一行中获取多个值。(subTable应该是一个新的标签。我试图实现的结果示例 谢谢你的建议
FICO SCORE
全部≥7600.50%0.375%0.25%0%-0.25%
产品740 -759 0.375%0.125%0%-0.375%-0.625%
720 - 739 0.25%-0.125%-0.375%-0.625%-1.00%
700 - 719 0.125%-0.375%-0.625%不符合条件
它们应该是多重的。 请参阅下面的代码 谢谢你的任何建议
`var updated = jQuery.parseJSON(localStorage.getItem("tableJson"));
function loop(obj, ul) {
$.each(obj, function(key, val) {
if(val && typeof val === "object") { // object, call recursively
var ul2 = $("<td>").appendTo(
$("<tr>").appendTo(ul)
);
loop(val, ul2);
} else {
$("<td style='background-color: orange; color: white;;'>", {
id: key
}).text(val).appendTo(ul);
}
});
}
var table = $("<table>");
loop(updated, table);
table.addClass("table").appendTo('#data');
} else {
$("<td style='background-color: orange; color: white;'>", {
id: key
}).text(val).appendTo(ul);
}
});
}
var table = $("<table>");
loop(updated, table);
table.addClass("table").appendTo('#data');
`
{
"table": [
{
"subTable": [
{
"line": [
"Fees"
]
},
{
"line": [
"Lender Fee",
"$895"
]
},
{
"line": [
"Tax Service Fee",
"$69"
]
},
{
"line": [
"Flood Certification Fee",
"$12"
]
},
{
"line": [
"Texas Doc Prep Fee",
"$150"
]
}
]
},
{
"subTable": [
{
"line": [
"Max of LTV/CLTV/HCLTV Ratio"
]
},
{
"line": [
"≤ 60",
"60.01-65",
"65.01-70",
"70.01-75",
"75.01-80"
]
}
]
},
{
"subTable": [
{
"line": [
"FICO Score"
]
},
{
"line": [
"All Eligible Products",
"≥ 760",
"0.50%",
"0.375%",
"0.25%",
"0%",
"-0.25%"
]
},
{
"line": [
"All Eligible Products",
"740 - 759",
"0.375%",
"0.125%",
"0%",
"-0.375%",
"-0.625%"
]
},
{
"line": [
"All Eligible Products",
"720 - 739",
"0.25%",
"-0.125%",
"-0.375%",
"-0.625%",
"-1.00%"
]
},
{
"line": [
"All Eligible Products",
"700 - 719",
"0.125%",
"-0.375%",
"-0.625%",
"Not Eligible",
"Not Eligible"
]
}
]
},
{
"subTable": [
{
"line": [
"Loan Amount"
]
},
{
"line": [
"All Eligible Products",
"Up to $1M",
"0.25%",
"0.25%",
"0.125%",
"0%",
"0%"
]
},
{
"line": [
"All Eligible Products",
">$1M Up to $1.5M",
"0.25%",
"0%",
"-0.125%",
"-0.25%",
"-0.375%"
]
},
{
"line": [
"All Eligible Products",
">$1.5M Up to $2M",
"0.125%",
"0%",
"-0.25%",
"-0.375%",
"Not Elig."
]
},
{
"line": [
"All Eligible Products",
">$2M Up to $2.5M",
"0%",
"-0.125%",
"Not Eligible",
"Not Eligible",
"Not Eligible"
]
}
]
},
{
"subTable": [
{
"line": [
"Loan Purpose/Occupancy/Property Type"
]
},
{
"line": [
"All Eligible Products",
"Purchase",
"0.25%",
"0.25%",
"0.25%",
"0.25%",
"0.250%"
]
},
{
"line": [
"All Eligible Products",
"Cash-Out Refinance",
"-0.250%",
"-0.250%",
"-0.250%",
"Not Eligible",
"Not Eligible"
]
},
{
"line": [
"All Eligible Products",
"Second Home",
"-0.125%",
"-0.25%",
"-0.375%",
"-0.75%",
"Not Elig."
]
},
{
"line": [
"All Eligible Products",
"2 Units",
"-0.25%",
"-0.25%",
"Not Eligible",
"Not Eligible",
"Not Eligible"
]
}
]
},
{
"subTable": [
{
"line": [
"Miscellaneous"
]
},
{
"line": [
"BE DTI > 40%",
"BE DTI > 40%",
"-0.625%",
"-0.625%",
"-0.625%",
"-0.625%",
"-0.625%"
]
},
{
"line": [
"Partial/No Impounds",
"All States",
"-0.15%",
"-0.15%",
"-0.15%",
"-0.15%",
"-0.15%"
]
},
{
"line": [
"Subordinate Financing",
"Subordinate Financing",
"-0.25%",
"-0.25%",
"-0.25%",
"-0.25%",
"-0.25%"
]
}
]
},
{
"subTable": [
{
"line": [
"Eligible Broker Incentives"
]
},
{
"line": [
"Tier",
"Super Elite",
"Elite",
"Gold",
"Silver",
"Bronze"
]
},
{
"line": [
"Elite Bonus",
"0.250%",
"0.125%",
"0%",
"0%",
"0%"
]
},
{
"line": [
"Ethos Edge*",
"0.125%",
"0.125%",
"0.125%",
"0%",
"0%"
]
},
{
"line": [
"Purchase Special (Purchase Primary Residence)",
"0.125%",
"0.125%",
"0.125%",
"0.125%",
"0%"
]
}
]
},
{
"subTable": [
{
"line": [
"Max Price (Including All Adjustments)"
]
},
{
"line": [
"Loan Amount",
"≤ $1M",
">$1M"
]
},
{
"line": [
"Fixed 30-Year",
"102.00",
"101.50"
]
},
{
"line": [
"Fixed 15-Year",
"101.50",
"101.25"
]
},
{
"line": [
"5/1 ARM",
"100.85",
"100.75"
]
},
{
"line": [
"7/1 ARM",
"100.85",
"100.75"
]
}
]
}
]
}