我在使用 SharePoint REST API 更新简单列表项时遇到问题。我已经浏览了所有博客以获得解决方案,但结果是一样的。当我使用 REST API 执行更新列表项函数时,它会向我返回我尝试更新的特定列表项行的正文,但它没有更新列表。有人可以帮我吗?提前致谢
function (listTitle, TabId, success, failure) {
var itemType = GetItemTypeForListName(listTitle);
var query = appweburl + "_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listTitle + "')/items(5)?&@target='" + hostweburl + "'";
var meta_data = {"__metadata": { "type": itemType }};
meta_data['DeletedStatus'] = 'Inactive'
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: query,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(meta_data),
//body: meta_data,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"IF-MATCH": "*"
//"content-length": meta_data.length,
},
success: function (data) {
//alert("success: " + JSON.stringify(data));
//deferred.resolve(JSON.parse(data.body));
console.log(JSON.stringify(data));
alert(JSON.stringify(data));
},
error: function (err) {
//alert("error: " + JSON.stringify(err));
console.log(JSON.stringify(err));
}
});
}
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
否则只需替换函数中的以下代码
executor.executeAsync({
url : query,
method : "POST",
body: JSON.stringify(meta_data),
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type" : "application/json;odata=verbose",
"X-HTTP-Method": "MERGE",
"IF-MATCH": "*"
},
success: function (data) {
console.log(JSON.stringify(data));
},
error: function (err) {
console.log(JSON.stringify(err));
} });
它还将为您插入摘要,因此您无需添加
"X-RequestDigest": $("#__REQUESTDIGEST").val(),