嗨,我想这将解释如何构建和发送批处理请求。您应该记住,这段代码片段是为SAPUI5 v1.28.x创建的,在此之后batchId不再受欢迎;)
另外,您应该记住,我使用的是ODataModel v2。下面是我用来创建这些调用的所有方法:
- 创建
- 更新
- 删除
sendBatchRequest:函数(itemsToBeRemoved,itemsToBeUpdated,itemsToBeCreated) { var控制器= this;var batchGroupId = "myBatchGroupId";var oModel = this.getView().getModel();var sKey = null;oModel.setUseBatch(true);//批处理请求为( sKey in itemsToBeCreated ){ oModel.create( itemsToBeUpdatedsKey.getPath(),itemsToBeUpdatedsKey.getData(),{ batchGroupId:])创建对象;}//批处理请求更新对象//合并将允许您使用deltas for( sKey in itemsToBeUpdated ){ oModel.update( itemsToBeUpdatedsKey.getPath(),itemsToBeUpdatedsKey.getData(),{ merge: true,batchGroupId: batchGroupId })部分更新对象;}//批处理请求删除对象( sKey in itemsToBeRemoved) { oModel.remove(itemsToBeRemovedsKey.getPath(),{ batchGroupId: batchGroupId });} oModel.setDeferredBatchGroups(batchGroupId);oModel.submitChanges({ batchGroupId: batchGroupId,success: function() ){console.log(“一切都很棒!”);},错误:函数(){console.log(“休斯顿我们有问题!”);}};}