我下面有一个函数可从托管元数据服务获取条款。一次调用函数,一切正常。但是如果我再打几次。它给出了致命错误“集合尚未初始化……”实际上,我使用“单页应用程序”,并且仅当我在开始时打开站点时才运行。我花了一整天的时间,可能需要在页面中调用该函数5至6次。有人可以帮忙吗?我的代码有什么问题?
var context = new SP.ClientContext(spContext.hostWeb.appWebUrl);
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStores = taxSession.get_termStores();
var termStore = termStores.getByName("Yönetilen Meta Veri Hizmeti");
var termSet = termStore.getTermSet(termsetguid);
var terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(sender, args) {
try {
var termEnumerator = terms.getEnumerator();
var termList = [];
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
termList.push(currentTerm.get_name());
}}
catch (e) {
common.logger.logWarning("Warning", "" , true);
}
}
function onQueryFailed(sender, args) {
common.logger.logError("", "Error", true);
}
谢谢
在以下情况下通常会发生此错误:
terms
根据您的情况)SP.ClientContext.executeQueryAsync
被循环调用。由于指定的函数是异步的,因此行为可能无法预测尝试将变量设置为局部变量(例如,使用匿名函数将其括起来)
(function(){
var context = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStores = taxSession.get_termStores();
var termStore = termStores.getByName(termStoreName);
var termSet = termStore.getTermSet(termsetGuid);
var terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded),Function.createDelegate(this, onQueryFailed));
})();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句