如何在sapui5中将OData模型转换为entityset

How to convert OData model to entityset in sap ui5

本文关键字:模型 转换 entityset OData 中将 sapui5      更新时间:2023-09-26

我想像在这个sapui5探索的示例中那样使用智能表,但问题是我有一个OData模型,该示例只显示了我们如何处理带有模拟数据的绑定,而且我不理解metadata.xml文件。我想oData模型也有自己的元数据文档。这是我在控制器中的代码:

this.DataPath = "QuarterPerformanceSet";
var oModel = new sap.ui.model.odata.ODataModel(model.Config.getServiceUrl(), true, model.user, password); 
oModel.setCountSupported(false);
oSmartTable.setModel(oModel);
oSmartTable.setEntitySet(this.DataPath);

但它不起作用。我得到了这个错误:

无法从加载Component-changes.json/Component-changes.json。检查"找不到文件"或分析错误。原因:未找到-

getChanges'失败:-

简单地说,我如何使用我的odata模型设置entitySet?

我的观点:

<smartTable:SmartTable id="idSmartTable" tableType="Table" 
useExportToExcel="true" useVariantManagement="false" 
useTablePersonalisation="true" header="Line Items" showRowCount="true"
persistencyKey="SmartTableAnalytical_Explored" enableAutoBinding="true"/>

如果有人能帮忙,请提前感谢。

更新2:我根据这个讨论重新绑定表

this.DataPath = "QuarterPerformanceSet";
var oModel = new sap.ui.model.odata.ODataModel(model.Config.getServiceUrl(), true, model.user, password); 
oModel.setCountSupported(false);
var oSmartTable = this.getView().byId("idSmartTable");
oSmartTable.setModel(oModel);
oSmartTable.setEntitySet(this.DataPath);
oSmartTable.rebindTable();

说起来很难过,但我还是犯了同样的错误。

您需要传递实体集的名称,而不是模型实例。例如,如果您定义了一个实体集客户,您只需执行以下操作:

oSmartTable.setEntitySet("Customers");

或者将属性entitySet添加到表声明中。

<smartTable:SmartTable id="idSmartTable" entitySet="ENTITY_SET" .../>