Sharepoint JSOM:set_item()没有update()

时间:2014-09-18 22:40:14

标签: sharepoint sharepoint-2010

我正在使用SharePoint Javascript对象模型(JSOM)。有人可以向我解释当set_item()未被调用时update()会做什么吗?

下面是一些代码来说明。

获取列表项的Boilerplate代码:

var ctx = SP.ClientContext.get_current();

var list = ctx.get_web().get_lists().getByTitle('Employees');
var listItems = list.getItems("");

ctx.load(listItems, "Include(Name, Role)");
ctx.executeQueryAsync(onSuccess, onFailure);

第一组命令

var first = listItems.getItemAtIndex(0);
var second = listItems.getItemAtIndex(1);

first.set_item("Role", "foo");
second.set_item("Role", "bar");

second.update(); // only call update on the second item
ctx.executeQueryAsync(onSuccess, onFailure);

对SharePoint的实际网络请求包含两个" SetFieldValue" " foo"的方法和" bar",只有一个"更新"第二种方法。 SharePoint仅使用" bar"。

更新了第二个值

第二组命令

first.update();
ctx.executeQueryAsync(onSuccess, onFailure);

第二个请求只包含一个Update方法。 SharePoint没有使用" foo"。

更新第一个值

问题

为什么即使未调用更新,也会发送第一个项目?

显然,当调用first.update()时,新值不会再次传递 - 但我至少会假设它将在SharePoint中暂存,等待update() - 但这并不是&#39}发生了。

谢谢!

1 个答案:

答案 0 :(得分:1)

执行update()提示后端主动替换/添加存储对象的值; set_item()将要更新的值和字段传递给服务器。两者都按预期工作,但在您明确使用update()之前,存储的信息不会发生实际更改。这可能是为了更好地利用批处理。