Javascript 我如何执行一个";“继续”;“中的语句”;。每一个;jQuery的功能?
请参考以下代码中的注释:Javascript 我如何执行一个";“继续”;“中的语句”;。每一个;jQuery的功能?,javascript,jquery,Javascript,Jquery,请参考以下代码中的注释: $('#btnDelete').on('click', function() { var treeView = $("#treeview").data("kendoTreeView"); var userId = $('#user_id').val(); $('#treeview').find('input:checkbox:checked').each(function() { debugger; v
$('#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 + '¬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'));
});
});
您正在查找
返回值
:
if (typeof notificationId == "undefined")
{
// exit the current function
return;
}
这会影响到下一次迭代,因为每次
只会为每次迭代调用匿名函数
return false;
非常简单,其工作原理与传统循环中的break
相同
编辑:对不起,您需要继续,而不是中断。很抱歉。请注意,您可以返回除
false
之外的任何内容以继续执行每个循环。谢谢,这就成功了。我可以在3分钟内接受你的回答。