0
我有一個上傳控件,每次成功上傳文件時都會觸發它。用戶可以隨時上傳1個或多個文件。並且以下js
功能被稱爲function OnFileUploadComplete(s, e){}
。在這個函數中,創建一個ajax調用並獲得一個值爲List<T>
的值。我要循環的結果從我的AJAX效應初探設置,並將其顯示到我已經做實現了表以下將項目添加一次到表
function successCallBack(result) {
var table = $("#attachments-table");
$.each(result.Attachment, function (index) {
var base64String = btoa(String.fromCharCode.apply(null, new Uint8Array(result.Attachment[index].Thumbnail)));
var rows = $('<tr></tr>'),
button = $('<input class="btn btn-danger delete-attachment">').attr({
type: 'button',
id: result.Attachment[index].Id,
name: result.Attachment[index].Id,
value: result.Attachment[index].Id });
rows.append('<td>' + result.Attachment[index].AttachmentName + '</td>');
rows.append('<td><img class="img-responsive" src="data:image/png;base64,' + base64String + '"></td>');
$('<td></td>').html(button).appendTo(rows);
table.append(rows);
});
}
這工作細到一個點。但是,如果我有多個項目,它會一遍又一遍地添加它們。所以我的問題是如何添加不在表中的項目。
注:在頁面加載時,由Ajax響應數據填充表是空的
是那些項目,獨特或重複,如果重複的意志?他們有相同的ID還是不同的? –
@subrahmanyabhat項目是唯一的,並且永遠不會有相同的標識,即使附件名稱是唯一的 – Code
然後每次向表格中添加新項目時都是如此。 –