无法让 ClientContext.executeQuery() 在 javascript 中工作

Jos*_*osh 4 javascript sharepoint-2010

我从共享点列表中获取信息,然后我想使用该数据。问题是我需要在使用 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)); 
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我将最后一行更改为:

context.executeQuery(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed)); 
Run Code Online (Sandbox Code Playgroud)

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

小智 5

我一直在尝试使用 ExecuteQuery 而不是 Async 版本的类似方法。从我发现的 JSOM 中不支持非 Async 版本。所以你必须使用 Async 版本。

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