首页 > 解决方案 > Sharepoint Rest API - 更新页面内列表的列

问题描述

我在 SitePages 中有一个包含列表的页面。我可以使用 (GET) /_api/web/lists/getbytitle('Site Pages')/items(29) 访问该页面

但是,在上面的 GET 响应中,列表没有显示,我如何访问页面内的列表?

我还需要更新该列表中所有行的列值,这可能吗?

提前致谢!塞尔吉奥

标签: sharepoint

解决方案


您可以获取页面内的列表,直接使用带有 Rest API 的列表标题,如下所示:

/_api/web/lists/getbytitle('ListTitleInsidePage')/items

因为 /_api/web/lists/getbytitle('Site Pages')/items(29) 将返回站点页面的元数据列,但不返回页面内的列表。

而如果要更新页面内的列表列,还是直接使用页面内的ListTitle:

$.ajax({  
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('List Name Inside Page')/items(Your record ID)",  
    type: "POST",  
    headers: {  
        "accept": "application/json;odata=verbose",  
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
        "content-Type": "application/json;odata=verbose",  
        "IF-MATCH": "*",  
        "X-HTTP-Method": "MERGE"  
    },  
    data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:"  
    Ur new input "}",  
    /*where Title is column name and add your desired new data*/  
    success: function(data) {  
        console.log(data.d.results);  
    },  
    error: function(error) {  
        alert(JSON.stringify(error));  
    }  
});  

并且如果需要更新所有行,请替换为上面请求中的item Id,使用Rest API一次更新所有行是不可用的。


推荐阅读