Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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 递归RestAPI调用呈现数据表上的数据循环错误_Javascript_Arrays_Json_Sharepoint Online_Restapi - Fatal编程技术网

Javascript 递归RestAPI调用呈现数据表上的数据循环错误

Javascript 递归RestAPI调用呈现数据表上的数据循环错误,javascript,arrays,json,sharepoint-online,restapi,Javascript,Arrays,Json,Sharepoint Online,Restapi,我需要进行递归RestAPI调用,以克服SharePoint online的5000视图阈值。下面的代码在生成前5000个条目后进入循环。它生成datatable,然后在循环中递增显示相同的数据。我的SharePoint列表中总共只有8800个条目 我只需要使用递归调用生成第一批5000个条目,然后生成第二批3800个条目,并在jquerydatatables中显示concat数据 $(document).ready(function() { var table = $('#ta

我需要进行递归RestAPI调用,以克服SharePoint online的5000视图阈值。下面的代码在生成前5000个条目后进入循环。它生成datatable,然后在循环中递增显示相同的数据。我的SharePoint列表中总共只有8800个条目

我只需要使用递归调用生成第一批5000个条目,然后生成第二批3800个条目,并在jquerydatatables中显示concat数据

$(document).ready(function() {
        var table = $('#table_id').DataTable({
            "pageLength": 100,
            "dom": 'Bfrtip',
            "buttons": [searchBuilder, copy],
            "aoColumns": [{"mData": "Created"}, {"mData": "EncodedAbsUrl"}]
        });
        
var response = response || [];

var listURL = "SPO_Site/_api/web/lists/getbytitle('List_Name')/items?$top=5000&$select=Created,EncodedAbsUrl";
GetListItemsRecursive(listURL);

function GetListItemsRecursive() {
    $.ajax({
        url: listURL,
        type: "GET",
        dataType: "json",
        headers: {
            "accept": "application/json;odata=verbose"
        },
        success: mySuccHandler,
        error: myErrHandler
    });
}

function mySuccHandler(data) {
    response = response.concat(data.d.results);
    console.log(data);
    if (data.d.__next) {GetListItemsRecursive(data.d.__next);}
    try {table.rows.add(response).draw();} 
    catch (e) {alert(e.message);}
}

function myErrHandler(data, errMessage) {alert("Error");}
});

我的测试报告供您参考:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.css">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script>
<script>
    $(document).ready(function () {
    
        var response = response || [];

        var listURL = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('testn')/items?$top=5000&$select=ID,Title";
        GetListItemsRecursive(listURL);

        function GetListItemsRecursive(listURL) {
            $.ajax({
                url: listURL,
                type: "GET",
                dataType: "json",
                async: false,
                headers: {
                    "accept": "application/json;odata=verbose"
                },
                success: mySuccHandler,
                error: myErrHandler
            });
        }

        function mySuccHandler(data) {

            console.log(data)
            response = response.concat(data.d.results.map(e=>[e.ID,e.Title]));
            
            console.log(response);
            if (data.d.__next) { GetListItemsRecursive(data.d.__next); }
            // try { table.rows.add(response).draw(); }
            // catch (e) { alert(e.message); }

        }
        function myErrHandler() {

        }
        $('#table_id').DataTable({
                data: response,
                columns: [
                    { title: "ID" },
                    { title: "Title" }
                ]
            });
    })
</script>
<table id="table_id" class="display"></table>

$(文档).ready(函数(){
var响应=响应| |[];
var listURL=_spPageContextInfo.webAbsoluteUrl+“/_api/web/lists/getbytitle('testn')/items?$top=5000&$select=ID,Title”;
GetListItemsRecursive(listURL);
函数GetListItemsRecursive(listURL){
$.ajax({
url:listURL,
键入:“获取”,
数据类型:“json”,
async:false,
标题:{
“接受”:“application/json;odata=verbose”
},
成功:mySuccHandler,
错误:MyerHandler
});
}
函数mySuccHandler(数据){
console.log(数据)
response=response.concat(data.d.results.map(e=>[e.ID,e.Title]);
控制台日志(响应);
if(data.d.uu next){GetListItemsRecursive(data.d.u next)}
//尝试{table.rows.add(response.draw();}
//捕捉(e){alert(e.message);}
}
函数myelhandler(){
}
$('#表_id')。数据表({
数据:答复,
栏目:[
{标题:“ID”},
{标题:“标题”}
]
});
})
测试结果: