可以't让ClientContext.executeQuery()在javascript中工作

Can't get ClientContext.executeQuery() to work in javascript

本文关键字:javascript 工作 executeQuery ClientContext 可以      更新时间:2023-09-26

我正在从共享点列表中获取信息,然后我想使用这些数据。问题是,在使用之前,我需要从Sharepoint服务器更新数据,但我无法使executeQuery()正常工作。不过,我可以让executeQueryAsync()正常工作。这是我的代码:

// Global variables;
var context;
var web; 
var list;
var howManyItem = 0;
var allItems;
var randNums = [];
// Initializes the variables; Sets listname; Gets all items; 
function init(){
    context = new SP.ClientContext.get_current();
    web = context.get_web();
    // Enter the list name;
    this.list = web.get_lists().getByTitle('LetsTalkAdded');
    // Get item count in the query/list;
    var query = SP.CamlQuery.createAllItemsQuery();
    allItems = list.getItems(query);
    context.load(allItems, 'Include(Title)');
    context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed)); 
}

这很好,但当我把最后一行改为:时

context.executeQuery(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed)); 

它不再工作,但我不能异步运行它们。如果我这样做,我的代码中依赖于该信息的部分将无法工作。为什么executeQuery()函数不起作用?

我一直在尝试类似的方法,使用ExecuteQuery而不是Async版本。根据我的发现,JSOM中不支持非异步版本。因此,您必须使用异步版本。

看着他的数字6。http://blogs.msdn.com/b/sharepointdev/archive/2011/07/19/working-with-the-ecmascript-client-object-model-jsom-in-sharepoint-2010-part-3-nikhil-sachdeva.aspx

executeQueryAsync无法填充全局变量。它的唯一用途是向用户显示警报。除此之外,它没有任何用处。