简体   繁体   English

如何在 UI5 中使用 JSON 模型属性作为 OData v4 列表绑定的路径

[英]How to use JSON Model Property as path for OData v4 List Binding in UI5

I try to display a list of objects from an OData V4 service in SAP UI5.我尝试在 SAP UI5 中显示来自 OData V4 服务的对象列表。 I would like to use a property from a JSON Model to set the binding path for the list items.我想使用 JSON 模型中的属性来设置列表项的绑定路径。

I thought I can just set the path in the items aggregation of the table:我以为我可以在表的项目聚合中设置路径:

<Table
  items="{
    path: '{appView>/dataPath}',
    parameters: {
      $count: true,
      $$updateGroupId: 'peopleGroup'
    }
  }">...</Table>

and of course define and set the model:当然还有定义和设置模型:

var oViewModel = new JSONModel({
  dataPath: "/People"
});

this.getView().setModel(oViewModel, "appView");

For some reason the data is not loaded.由于某种原因,数据未加载。 There is not even items binded to the table:甚至没有项目绑定到表:

oTable.getBinding("items");  // undefined

The JSON Model is defined in the init method of the controller. JSON 模型在控制器的 init 方法中定义。

Anybody has an idea why this is not working?任何人都知道为什么这不起作用?

As per my understanding you want to bind path dynamically.in such case you can write template in xml without any path then in controller you have write bind path XML View:根据我的理解,您想动态绑定路径。在这种情况下,您可以在没有任何路径的情况下在 xml 中编写模板,然后在控制器中编写绑定路径 XML 视图:

<Table id="tblData" items="{}"> <items> **template code ** </items> </Table>

Controller:控制器:

var oTable = this.getView().byId("tblData"),
    sPath = this.getModel("appView").getProperty("/dataPath"),
    oBinding = oTable.bindItems({path: sPath});

for filters:对于过滤器:

oBinding.filter(aFilters);
items: "{ path: '{appView>/dataPath}',

Anybody has an idea why this is not working?任何人都知道为什么这不起作用?

Binding definitions apply only for ManagedObject's properties and aggregations.绑定定义适用于 ManagedObject 的属性和聚合。 As path is just a plain object property, trying to bind anything there will be ignored.由于path只是一个普通的对象属性,尝试绑定任何东西都会被忽略。

Since you want to bind the Table to the result of the {appView>/dataPath} binding, I think you need to use Expression Binding to solve this.既然你想将表绑定到的结果{appView>/dataPath}绑定,我认为你需要使用表达式绑定来解决这个问题。

items="{
    path: '{= ${appView>/dataPath}}',
    parameters: {
      $count: true,
      $$updateGroupId: 'peopleGroup'
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM