我嘗試接收SharePoint中用戶子網站的子網站。 在第一次接收子網站(函數getSubWebs())時,一切正常:子網站已收到,我可以遍歷它們。該集合尚未初始化getEnumeration的第二個電話
但是我嘗試使用相同類型的代碼獲取這些網站的子網頁 var webSubEnumerator = subwebCollection.getEnumerator();之前引發錯誤
The collection has not been initialized
即使我使用load()和是ExecuteQueryAsync的「成功」雙組分(就像在腹板父請求)內。
什麼可能導致問題在這裏?
var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
var web = context.get_web();
var lists = web.get_lists();
var parrentwebCollection = null;
ExecuteOrDelayUntilScriptLoaded(getSubWebs, "sp.js");
function getSubWebs(){
parrentwebCollection = web.getSubwebsForCurrentUser(null);
context.load(parrentwebCollection)
context.executeQueryAsync(onGetSubwebsSuccess, onGetSubwebsFail);
}
function onGetSubwebsSuccess(sender, args){
var webEnumerator = parrentwebCollection.getEnumerator();
// Everything works FINE on this getEnumerator()
while (webEnumerator.moveNext()){
var webParrent = webEnumerator.get_current();
var parrenttitel = webParrent.get_title();
var parrenturl = webParrent.get_url();
//Load Subs From Parrent
var subwebCollection = null;
subwebCollection = webParrent.getSubwebsForCurrentUser(null);
if (subwebCollection != undefined && subwebCollection != null) {
context.load(subwebCollection);
context.executeQueryAsync(onGetSSubwebsSuccess, onGetSSubwebsFail);
function onGetSSubwebsSuccess(sender, args) {
console.log("getSubWebs query successful")
var webSubEnumerator = subwebCollection.getEnumerator();
// THIS getEnumerator(), however throws an exception
while (webSubEnumerator.moveNext()){
console.log("After While")
var subweb = webSubEnumerator.get_current();
var subtitel = subweb.get_title();
}
}
function onGetSSubwebsFail(sender, args){
alert("Request to retrieve subwebs failed. Error: " + args.get_message())
}
}
}
}
function onGetSubwebsFail(sender, args){
alert("Request to retrieve subwebs failed. Error: " + args.get_message())
}
請注意,我是成功的()內 - 的executeQueryAsync().
功能,所以我相信這不是典型的「嘗試讀取異步數據之前,它是有」 - 問題。