如何在jQuery的".EACH"函数中执行"CONTINUE"语句?

RJ.*_*RJ. -1 javascript jquery

请参阅以下代码中的评论:

$('#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 the notification ID is "undefined" here, I want the ".EACH" 'loop' to continue to the next item.
        }
        $.ajax(
            {
                url: '../api/notifications/deleteNotification?userId=' + userId + '&notificationId=' + 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'));

    });
});
Run Code Online (Sandbox Code Playgroud)

McG*_*gle 7

您正在寻找return:

if (typeof notificationId == "undefined")
{
    // exit the current function
    return;
}
Run Code Online (Sandbox Code Playgroud)

这具有继续下一次迭代的效果,因为each只需为每次迭代调用匿名函数.