我终于找到了错误。字段名正确为“lookup1”,但当我更新此字段的值时,需要在字段名后添加后缀“Id”。我的案例应该是“lookup1Id”,它是有效的。
function Update(result) {
var item = $.extend({
"__metadata": { "type": "SP.Data.Test_x0020_listListItem" }
}, {
Title: "test item aaaa",
lookup1Id: { "results": [1, 3] }, //here is the problem, it should be "lookup1Id"
});
$.ajax({
url: result.d.__metadata.uri,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": result.d.__metadata.etag
},
success: function (result) {
console.log(result);
},
error: function (error) {
console.log(error);
}
});
}