答案 0 :(得分:0)
我稍微更改了您的代码,因此它可以在JSBin中运行。
服务http://services.odata.org/V2/(S(2pxev2v2zqtidlzbqzhncots))/OData/OData.svc/Categories不支持DELETE的批量请求。请参阅响应正文。如果要进行多次删除,可以使用ODataModel.remove逐个发送多个DELETE问题
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en-US">
Content is unexpected for the Delete operation.
</message>
</error>
同样对于submitBatch(fnSuccess?, fnError?, bAsync?)
,文件指出:
{function} fnSuccess?
您必须检查成功函数回调中的参数aErrorResponses
,以查看是否发生了任何错误。有关批量删除和检查错误响应,请参阅以下内容。
var indices = oTable.getSelectedIndices();
if (indices.length == 0) {
alert("Please Select a row to Delete");
return;
} else {
alert("selected " + indices);
var batchChanges = [];
for (var i = 0; i < indices.length; i++) {
var selectedRow = oTable.getRows()[i];
var selectedId = selectedRow.getCells()[0].getValue();
var selectedName = selectedRow.getCells()[1].getValue();
var del = m.createBatchOperation(
"Categories(" + selectedId + ")",
"DELETE"
);
batchChanges.push(del);
}
m.addBatchChangeOperations(batchChanges);
m.submitBatch(function(oData, oResponse, aErrorResponses) {
if (aErrorResponses.length > 0) {
alert(aErrorResponses[0].response.body);
} else {
m.refresh();
m.clearBatch();
alert("success");
}
}, function(err) {
alert("error occured");
});
}