對不起,你們。我真的很討厭不得不問這個問題。我保證,我已經經歷了許多其他問題,因爲我的耐心允許,所以甚至看起來與切線相關。承諾解決後無法進入JSON響應
繼從下面的問題代碼:
- jQuery when each is completed, trigger function
- jQuery AJAX solution inside each() loop
- How do I return the response from an asynchronous call?
我有以下幾點:
var XHR = [];
//This parses some selections on a screen, which, in turn, informs the URL inside the loop.
$("#list > input:checkbox:checked").each(function(){
result = [];
var list = $(this).val();
XHR.push($.ajax({
type:'GET',
url:"https://a-place.com/subsite/webapp/_api/web/lists/getByTitle('"+list+"')/items?$select=" + select + "&$filter=" + filter + "&$expand=" + expand + "&$top=10000",
dataType: "json",
headers: {Accept:"application/json;odata=verbose"},
complete:function(data){}
}));
});
$.when(XHR).then(function(data){
console.log(data);
});
無論我做什麼,我都會得到那裏的承諾。我無法對它們做任何事情,試圖訪問所有實際對象所在的responseJSON屬性,什麼都不做。我已經嘗試在完整的回調函數中添加一個return語句,它看起來並沒有改變實際被推入XHR數組的內容。
理想情況下,應該從一個或多個匹配選定選項的SharePoint列表中返回一堆列表項,並將匹配項放入一個單獨的數組中,我可以使用這些數據。
編輯
嗯。好吧,根據建議,我已經試過:
success:function(data){}
而且
success:function(data){return data.d.results;}
並沒有什麼真正的控制檯改變,無論我是否使用$ .when.then或.done。
在此先感謝。
想,也許你想'.done(...)'代替如果'。然後(...)' –
我欣賞這個建議,但我已經試過了。相同的確切結果。 – ChrisPEditor
而不是返回成功回調的結果,嘗試將其推入數組。 'result.push(data.d.results);'然後在「then」函數中,您將知道您已準備好所有結果,並且可以使用它。這裏不是奇特的解決方案,但應該工作。 –