我有一个我无法弄清楚的问题。我有一个 ajax 成功函数,它遍历一个多维数组,如下所示:
function onSuccessClientCustomerData(data) {
// Count length of object
var count = 0;
for (i in data) {
if (data.hasOwnProperty(i)) {
count++;
}
}
// Fetch data
var arr = new Array(data.variable0, data.variable1, data.variable2, data.variable3, data.variable4);
for(var i = 0; i< count; i++) {
var variable = $.parseJSON(arr[i]);
}
}
我每个数组都有三个键,我想在每一行上填充 td:eq(1) 到 td:eq(2):
<table id="test">
<tr>
<td><input type="text"></td>
<td class="outputName">-</td>
<td class="outputRating">-</td>
<td class="outputTurnover">-</td>
</tr>
<tr>
<td><input type="text"></td>
<td class="outputName">-</td>
<td class="outputRating">-</td>
<td class="outputTurnover">-</td>
</tr>
</table>
我怎么做。我已经尝试了每个功能,但无法让它工作!
将不胜感激任何帮助或参考阅读!
谢谢!
编辑/这是我的解决方案
function onSuccessClientCustomerData(data) {
// Count length of object
var count = 0;
for (i in data) {
if (data.hasOwnProperty(i)) {
count++;
}
}
// Fetch data
var arr = new Array(data.variable0, data.variable1, data.variable2, data.variable3, data.variable4);
for (var i = 0; i < count; i++) {
var arr_j = $.parseJSON(arr[i]);
$("#row" + i + " .key0").html(arr_j.name);
$("#row" + i + " .key1").html(arr_j.rating);
$("#row" + i + " .key2").html(arr_j.percentOfTotalIncome);
}
}