获取“oModel.read不是函数”错误

问题描述 投票:1回答:2

V4 ODatamodel上执行Read操作时,我收到一个错误说法

oModel.read不是一个函数

Model declaration

错误

Error screenshot

如果我做错了,请告诉我如何纠正。

odata sapui5 odata-v4
2个回答
2
投票

预计会出现此错误。

oData Model V4中不存在read方法。

见下文: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"
});

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"
  */
  });
© www.soinside.com 2019 - 2024. All rights reserved.