【问题标题】:SharePoint 2013: REST API, GET JSON, Display List ItemsSharePoint 2013:REST API、GET JSON、显示列表项
【发布时间】:2016-09-21 14:16:57
【问题描述】:

我在 SharePoint 2013 的列表中使用 AJAX 获取 JSON,我成功获取了信息。我的问题在于显示上述信息。我得到了要显示的 78 个项目的数组,我还通过警报和控制台enter image description here 确认了信息,但是我几乎将显示的附加项目数量增加了一倍,其值为“未定义”。我需要帮助来弄清楚为什么会这样,以及如何删除显示的多余项目。我对使用 AJAX 和 REST 还很陌生,因此我们将不胜感激!

    function getData()
    {
        var $data = $('#data')
        $.ajax({
        type: "GET",
        dataType: "json",
        cache: false,
        url: "https://url.com/.../.../...",

        success: function(data)
        {

            console.log(data);
            alert("Data Loaded: " + JSON.stringify(data));
            $.each(data, function(index,item){
                $.each(this, function(index, item)
                    {
                    $data.append('<dl><dt> Event Date: </dt>' + item.EventDate + ' <dt>Subheading:</dt> ' + item.Subheading + '<dt> StatusInput: </dt>' + item.StatusInput + ' <dt> ReportIn: </dt>' + item.ReportIn + '<dt> Org: </dt>' + item.Org + '<dt> Start Reporting: </dt>' + item.StartReporting + '<dt> Stop Reporting: </dt>' + item.StopReporting + '<dt> Org Parent: </dt>' + item.OrgParent + '<dt> Modified: </dt>' + item.Modified + '</dl>');});
        });     
        }// end SUCCESS function
     });  

【问题讨论】:

    标签: jquery arrays ajax rest sharepoint-2013


    【解决方案1】:

    所以我通常会使用 for 循环,但下面的代码 sn-p 应该会有所帮助。我怀疑您获得两组结果的原因与您的嵌套 $.each() 有关。

    success: function(data){
        //Results are stored inside of the results object.
        var results = data.d.results;
    
        //Sometimes helps to log results to console. Helps
        //to see what the specific column names.
        console.log(results);
    
        $.each(results, function(index, item){
    
            //Try using your append here. 
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-08
      • 2015-11-30
      • 2014-11-21
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 2013-06-06
      • 2020-10-02
      • 1970-01-01
      相关资源
      最近更新 更多