2
以下代碼獲取JSON對象,然後將其內容吐出到<table>
中。我第一次這樣做,我的JSON內容就好了。但是,當我刷新時,刷新的數據卡在我的桌子底部。如何刷新數據以僅顯示新數據?我嘗試使用.remove()
,但有一個明顯的刪除,然後刷新數據。使用jQuery後的刷新表.append()
$(function() {
$('#ReportedIssue').change(function() {
//$('.data').remove()
$.getJSON('/CurReport/GetUpdatedTableResults', function(json) {
for (var i = 0; i < json.GetDocumentResults.length; i++) {
$('#DocumentInfoTable').append(
"<tr class='data'>" +
"<td>" + json.GetDocumentResults[i].Document.DocumentId + "</td>" +
"<td>" + json.GetDocumentResults[i].Document.LanguageCode + "</td>" +
"<td>" + json.GetDocumentResults[i].ReportedIssue + "</td>" +
"<td>" + json.GetDocumentResults[i].PageNumber + "</td>" +
"</tr>"
);
};
});
});
});
謝謝
亞倫
更有效的方法是構建一個片段列表('var str = []; ...; str.push(fragment);'),然後執行'$(...)。html(str.join(' '));'因爲那樣你就不必做太多的字符串處理。 – rfunduk 2010-03-29 21:11:59