2017-04-14 9 views
1

AJAX呼び出しによって設定されたリスト内に削除ボタンがあります。これらのボタンは、確認ダイアログをトリガすることを想定していますが、このクリックイベントハンドラで呼び出されたときに確認ダイアログを表示することはできません。別のハンドラが必要ですか?私は誰かが私を解決策に導くことを願っています。添付イベントハンドラのJquery confirm()

$('#list').on('click', '.btnRemoveNote', function() {     
       $(this).confirm({ 
        msg: 'Do you really want to remove this?' 
       });      
      }); 

これはリストが

function funcLoadList(racodeID) { 
    if (racodeID == null || racodeID == '') { console.log('bypassing list load, racodeid was null'); return; } 
    console.log("Load List function initiated for " + racodeID); 
    $('.table-row').remove(); 
    var url = '<%= Url.Action("MemberGetNoteList", "AccessCodes") %>'; 
    var downloadUrl = '<%= Url.Action("MemberDownloadNoteDocument", "AccessCodes") %>'; 

    $.ajax({ 
     url: url, 
     data: { RacodeID: racodeID }, 
     beforeSend: function() { 
      $('#listStatus').text('Updating List...'); 
     }, 
     complete: function() { 
      // $('#fileStatus').text('Request complete...'); 
     }, 
     dataType: 'json', 
     url: url, 
     async: false, 
     type: 'POST', 
     error: function (xhr, status, errorThrown) { 
      $('#listStatus').text('Sorry, there was a connection error: ' + xhr.status + '\n Please try again later.'); 
      console.log('There was a error: ' + xhr.status + ' - ' + xhr.responseText); 
      return errorThrown; 
     } 
    }) 
    .done(function (data) { 
     $('#list').show(); 
     $('.list-no-note').remove(); 

     if (data == '') { 
      $('#list').hide(); 
      $('#listContainer').append('<div class="list-no-note">There are no notes for this member. Use the "Add Member Note/Document" area to add your first note.</div>'); 
      $('.exportNotesLink').hide(); 
     } 
     else { 


      $.each(data, function (i, item) { 
       var followRequired = false; 
       var followUpBtn = ''; 
       var followUpInfo = ''; 
       var commentArea = ''; 

       if (item.followUpEmailSentOn != null) 
        followUpInfo = new Date(parseInt(item.followUpEmailSentOn.substr(6))); 

       var fulfilledBtn = '<span class="fulfill unfulfilled" >Fulfilled</span>'; 
       item.dateCreated = new Date(parseInt(item.dateCreated.substr(6))); 

       if (item.followUpDate != null) { 
        followRequired = true; 
        item.followUpDate = new Date(parseInt(item.followUpDate.substr(6))); 

       } else { item.followUpDate = "N/A"; } 

       if (item.isFulfilled) { 
        fulfilledBtn = '<span class="fulfill fulfilled" >Fulfilled</span>'; 
       } else { 
        fulfilledBtn = '<span class="fulfill unfulfilled" >UnFulfilled</span>'; 
       } 

       if (!item.followUpEmailSent && item.followUpDate != 'N/A' && !item.isFollowedUp) { 
        followUpBtn = '<img src="<%= ResolveUrl("~/Content/Images/Icons/followup_icon.png") %>" class="followUpBtn" title="A followup is scheduled for ' + item.followUpDate + '" />'; 
       } 

       if (item.followUpEmailSent && item.followUpDate != 'N/A' && item.followUpEmailSentOn != null) { 
        followUpInfo = '<img src="<%= ResolveUrl("~/Content/Images/Icons/checkmark.png") %>" height="20px" style="vertical-align:middle"/><span style="color:green">A Follow-up email was sent on ' + followUpInfo + ' to ' + item.followUpEmail + '</span>'; 

       } 

       if (item.comment != null && item.comment != '') { 
        commentArea = '<b>Comment:</b><span class="noteComment" > ' + item.comment + '</span><br /><br />'; 
       } 
       //console.log("inside loop..."); 
       var table; 
       var shortFileName; 
       var iconFile = ''; 
       var followupDate = ''; 

       if (item.fileName != '' && item.fileName != null && item.fileName.length > 25) 
        shortFileName = jQuery.trim(item.fileName).substring(0, 25).trim(this) + "..."; 
       else 
        shortFileName = item.fileName; 

       if (shortFileName != '' && shortFileName != null) { 
        iconFile = '<img src="<%= ResolveUrl("~/Content/Images/Icons/text_icon.png") %>" height="20px" title="Download this document" class="masterTooltip" style="vertical-align:middle"/>'; 
       } 

       if (item.followUpDate == null) 
        followupDate = 'N/A'; 
       else 
        followupDate = item.followUpDate; 


       var tr = (
       '<tr style="border-top:1px solid gray" class="table-row">' + 
       '<td class = "' + item.ID + '"> ' + fulfilledBtn + '</td>' + 
       '<td>&nbsp;</td>' + 
       '<td><span class="NoteDesc">' + item.description + '</span></td>' + 
       '<td>' + item.requestTakenBy + '</td>' + 
       '<td align="right"><a class="btnRemoveNote"><img class="' + item.ID + '" src="<%= ResolveUrl("~/Content/Images/Icons/delete-icon.png") %>" /></a></td>' + 
       '<td>&nbsp;</td>' + 
       '</tr>' + 
       '<tr class="table-row">' + 
       '<td colspan = "2" >' + followUpBtn + '</td>' + 
       '<td colspan="3" >' + commentArea + iconFile + '<a class="downloadUserFile"><span class="' + item.ID + '">' + shortFileName + '</span></a></td>' + 
       '<td></td>' + 
       '</tr><tr class="table-row">' + 
       '<td colspan="6" style="padding-left:30px;padding-right:20px;padding-bottom:10px;"><i><b>Follow-up Date:</b> ' + item.followUpDate + '</i></td></tr>' + 
       '</tr><tr class="table-row">' + 
       '<td colspan="6" style="padding-left:30px;padding-right:20px;padding-bottom:10px;">' + followUpInfo + '</td></tr>' + 
       '<script>$(".btnRemoveNote").confirm({msg: "Do you really want to remove this? "});<\/script>' 
        ); 

       $('#list').append(tr); 

      }); 
     } 
    }); 

    $('#listStatus').text(''); 
    console.log("Load List function complete..."); 
    return true; 
} 
+0

プラグインを使用していない限り、jQueryによる確認方法はありません。プラグインを使用している場合は、プラグインのドキュメントが表示されます。エラーのコンソールを確認してください – charlietfl

+0

最初のコメントに加えて、ボタンを作成する方法を投稿してください。これは、あなたのajaxコールチェックの後にイベントバインディングの問題になる可能性があります。[this](http://stackoverflow.com/questions/203198/動的に作成されたイベントバインディング) –

答えて

0

ちょうどJavaScriptの確認を使用して生成される方法です。

$('#list').on('click', '.btnRemoveNote', 
    function() {     
    confirm('Do you really want to remove this?'); 
    }      
); 

私はちょうどより多くのパラメータを持つ.dialog、jQueryのには$(この).confirmは()がないと思います。 hereを読んでください。あなたが望むなら、それを使うことができます。

+0

jquery.confirm.jsプラグインを使用しています。ここでは、このプラグインをアプリケーション内の他のいくつかの領域で使用していますので、ここで使用したいと思います。エラーは生成されず、レコードは単に確認なしで削除されます。 – user2751629

関連する問題