2017-03-08 1 views
0

파일을 성공적으로 업로드 할 때마다 업로드 제어가 적용됩니다. 사용자는 언제든지 하나 이상의 파일을 업로드 할 수 있습니다. 그리고 다음과 같은 js funciton은 function OnFileUploadComplete(s, e){}이라고합니다. 이 함수에서 ajax를 호출하고 List<T> 값을 얻습니다. 내 아약스 reponse에서 결과 집합을 통해 루프를 원하고테이블에 한 번만 항목을 추가하십시오.

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); 
    }); 
} 

이 점에 잘 작동 다음 내가 수행하여 달성 한 테이블로 표시됩니다. 그러나 여러 항목이있는 경우 여러 항목을 반복해서 추가합니다. 그래서 내 질문은 어떻게 테이블에 아직없는 항목을 추가 할 수 있습니다.

참고 : 페이지가로드와는 아약스 응답 데이터에 의해 채워지면 표는

+0

같은 것을 시도 비어 반복적 인 의지 그들은 같은 이드 또는 다른가? –

+0

@subrahmanyabab 항목이 고유하고 동일한 ID를 갖지 않습니다. 첨부 파일 이름이 고유 한 경우에도 테이블 오른쪽에 새 항목을 추가 할 때마다 – Code

+0

입니다. –

답변

1

고유 또는 반복적 해당 항목, 경우는이

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); 
if($("#"+id).length==0){ 
      table.append(rows);} 
    }); 
} 
+0

이것은 내가 찾던 것입니다. 고마워요! – Code

관련 문제