Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript检索多个sharepoint列表_Javascript_Sharepoint_Csom_Sharepoint List - Fatal编程技术网

使用javascript检索多个sharepoint列表

使用javascript检索多个sharepoint列表,javascript,sharepoint,csom,sharepoint-list,Javascript,Sharepoint,Csom,Sharepoint List,我只是想知道在同一个函数中加载多个列表是否是一个好主意,因为它们都使用相同的成功回调,代码示例: function retrieveListItems() { var clientContext = new SP.ClientContext.get_current(); var camlQuery = new SP.CamlQuery.createAllItemsQuery(); employerList = clientContext.get_web().get_li

我只是想知道在同一个函数中加载多个列表是否是一个好主意,因为它们都使用相同的成功回调,代码示例:

function retrieveListItems() {

    var clientContext = new SP.ClientContext.get_current();
    var camlQuery = new SP.CamlQuery.createAllItemsQuery();
    employerList = clientContext.get_web().get_lists().getByTitle('Employer Partners').getItems(camlQuery);
    pocList = clientContext.get_web().get_lists().getByTitle('Points of Contact').getItems(camlQuery);

    var lists = [employerList, pocList];
    for (var i = 0; i < lists.length; i++) {
        clientContext.load(lists[i]);
    }

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );
}

代码在某些情况下运行,但由于集合尚未初始化而失败。尚未请求或请求尚未执行。可能需要明确请求。在其他情况下。

尝试使用jquery ajax,创建一个返回ajax承诺的函数,然后调用.then方法并执行第二个请求,这样您就不会在检索项目时遇到异步问题

查看此项了解更多信息:

希望这有帮助