我一直在努力研究這一整天,還沒有得到它。我有這樣的代碼來加載和顯示一些JSON數據:JQuery - 奇數整數/字符串問題
var id = firstLevel.id;
$.each(thirdLevel, function(index4, fourthLevel) {
$('#'+id+' tr:nth-child('+currentRow+')').append("<td>M "+fourthLevel.male+"</td>");
$('#'+id+' tr:nth-child('+currentRow+')').append("<td>H "+fourthLevel.herm+"</td>");
currentRow++;
console.log(id);
});
它應該使用表的ID插入新列到行(我有很多不同ID的每一個表),但「 ID」變量似乎並沒有被正確的工作,而我在打印到控制檯,它具有正確的值(421在第一次迭代)
現在,如果我這樣做:
var id = 421;
$.each(thirdLevel, function(index4, fourthLevel) {
$('#'+id+' tr:nth-child('+currentRow+')').append("<td>M "+fourthLevel.male+"</td>");
$('#'+id+' tr:nth-child('+currentRow+')').append("<td>H "+fourthLevel.herm+"</td>");
currentRow++;
console.log(id);
});
它將工作,並將所有新列插入ID爲421的桌子上...
那麼,我的代碼有什麼問題嗎? 非常感謝!
定義「不工作的權利」。 –
你在做什麼「男性」和「herm」都是選擇?大聲笑 – Jason
會很高興知道什麼firstLevel是 –