javascript - How do I execute a "CONTINUE" statement inside a ".EACH" function of jQuery? -
please refer comment inside code below:
$('#btndelete').on('click', function() { var treeview = $("#treeview").data("kendotreeview"); var userid = $('#user_id').val(); $('#treeview').find('input:checkbox:checked').each(function() { debugger; var li = $(this).closest(".k-item")[0]; var notificationid = treeview.datasource.getbyuid(li.getattribute('data-uid')).id; if (notificationid == undefined) { //if notification id "undefined" here, want ".each" 'loop' continue next item. } $.ajax( { url: '../api/notifications/deletenotification?userid=' + userid + '¬ificationid=' + notificationid, type: 'delete' }).done(function() { var treeview = $("#treeview").data("kendotreeview"); treeview.destroy(); createnotificationtree(userid); console.log('delete successful.'); }).fail(function(jqxhr, status, error) { console.log("error : " + error); }); treeview.remove($(this).closest('.k-item')); }); });
you're looking return
:
if (typeof notificationid == "undefined") { // exit current function return; }
this has effect of going on next iteration, because each
invokes anonymous function each iteration.
Comments
Post a Comment