从 oTable.bindItems 捕获 oData 错误

Catch oData errors from oTable.bindItems

我在 JavaScript 中建立了一个 table 因此:

oTable.bindItems({
    path: oQuery,
    template: this.getFragment("<fragment>"),
    filters: aFilter
});

有没有办法像执行 oModel.read 时那样捕获从 odata 调用返回的错误,您可以指定成功和错误函数?

这个参考好像没有提到:https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.base.ManagedObject.html#bindAggregation

也许我遗漏了什么。

我们有 2 种方法来检查 oData 故障:

  1. 附加元数据失败。 (https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#attachMetadataFailed)
  2. attachRequestFailed。

让我们以选项 2 为例(因为我确定您将拥有有效的 oData 服务)。

服务:http://services.odata.org/Northwind/Northwind.svc/

注意Employees 是上述 Northwind 服务中的有效实体集。

我将尝试将我的 table 与 错误的 实体集名称绑定,例如:MyEmployees.

现在,将我的 table 绑定到 MyEmployees 会抛出我们需要捕获的错误。以下是工作代码:

查看:

<Table items = "{/MyEmployees}">

控制器:

        var url = "proxy/http/services.odata.org/Northwind/Northwind.svc/";

        var oDataModel = new sap.ui.model.odata.ODataModel(url);

        oDataModel.attachRequestFailed(function(e) {
            console.log('request  failed');
        });

        this.getView().setModel(oDataModel);

继续尝试。让我知道这是否有帮助。 :)