出现“ oModel.read不是函数”错误

时间:2018-09-03 15:20:05

标签: odata sapui5 odata-v4

V4 ODatamodel上执行读取操作时,出现错误提示

  

oModel.read不是函数

代码

Model declaration

错误

Error screenshot

如果我做错了什么,请让我知道如何纠正。

2 个答案:

答案 0 :(得分:2)

此错误是预期的。

  

oData Model V4中不存在读取方法。

参见下文: read is not a function in V4

但是,您可以使用oData V2进行相同的操作(推荐的方法用于oData,因为V4仍然缺少一些功能)

Restrictions with oData V4

oData V2 vs oData V4

不过,如果以后需要将响应项与表绑定,则可以 这样做:

var oModel = new sap.ui.model.odata.v4.ODataModel({
    groupId: "$auto",
    serviceUrl: "url",
    synchronizationMode: "None",
    operationMode: "Server"
  }),
  oSettings = new sap.ui.model.json.JSONModel({
    bOnlyLarge: false,
    bFilterGermany: false
  });
var oTable = new sap.ui.table.Table({
  columns: [{
    label: "ProductName",
    template: new sap.m.Text({
      text: "{Country}"
    }),
    sortProperty: "ProductName"
  }]
});
oTable.setModel(oModel);

oTable.bindRows({
  path: "/Products"
});

答案 1 :(得分:0)

var oModel = new sap.ui.model.odata.v4.ODataModel({
    /* send requests directly. Use $auto for batch request wich will be send automatically on before rendering */
  groupId : "$direct",
    /* I'll just quote the API documentary:
  Controls synchronization between different bindings which refer to the same data for the case data changes in one binding.
  Must be set to 'None' which means bindings are not synchronized at all; all other values are not supported and lead to an error.
  */
  synchronizationMode : "None",
  /*
  Root URL of the service to request data from.
  */
    serviceUrl : "http://services.odata.org/TripPinRESTierService/",
  /*
  optional. Group ID that is used for update requests. If no update group ID is specified, mParameters.groupId is used.:
  updateGroupId : "$direct"
  */
  });