我有一些正在被调用的代码,它遍历我的$ .ajax()的开头,在退出并进入下一部分之前,我需要它遍历整个方法,因为直到将其正确组合为止它一直贯穿目前它开始,然后退出并跳过我的延迟,并进入if(woimageindex> = 0)条件
这是我的代码。我需要if(woimageindex == -1)来运行并通过defer.done(function(){,但它跳过了本节中的所有内容。在继续之前,我该如何做到这一点?
if (woimageindex == -1)//item not found
{
var ajaxRequests = [];
url = rootPath + "utility/GetWebRequestImages";
ajaxRequests.push($.ajax({
type: 'POST',
url: url,
data: {
corp_id: WOCorp_id
},
dataType: 'json'
}));
var defer = $.when.apply($, ajaxRequests);
defer.done(function () {
// This is executed only after every ajax request has been completed
$.each(arguments, function (index, responseData) {
switch (index) {
case 0://status
//populate the AutoCompleteDataSource with the data from server
arrWOWebRequestImagesList.push(new PickListModel(WOCorp_id, responseData));
woimageindex = arrWOWebRequestImagesList.length - 1;
break;
}
//alert(index);
});//end of switch
});//end of defer
}
if (woimageindex >= 0)
{
var categories = arrWOWebRequestImagesList[woimageindex].list;
alert(categories.length);
var list = [];
// added new PickListModel(webimage_id, after .push(
//list.push(new PickListModel(webimage_id, $.map(arrWOWebRequestImagesList[woimageindex].list, function (item) {
list.push( $.map(arrWOWebRequestImagesList[woimageindex].list, function (item) {
return new PickListItem(item.caption, item.caption, item.webimage_id);
}));