我在使用SharePoint REST API更新简单列表项时遇到问题。我已经浏览了所有博客以获得解决方案,但结果是一样的。当我使用REST API执行更新列表项功能时,它返回我正在尝试更新的特定列表项行的主体但它没有更新listem。请有人帮帮我。提前致谢
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";
}
答案 0 :(得分:1)
否则只需替换函数中的以下代码
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(),