在 xml 聚合绑定中使用模型变量

Use a model variable inside xml aggregation binding

我正在尝试使用 TreeTable 绑定到带过滤器的 OData。但是过滤器值在另一个模型中。 post 是关于 XML 视图绑定的。

模型 1(通过导航参数获取):

{
  locationID: 'MD',
  locationName: 'My location'
}

所以我的树 table:

<table:TreeTable rows="{
      path: '/Model2',
      filters: [
          {
              path: 'LOC_ID',
              operator: 'EQ',
              value1: '{Model1>/locationID}'
          }
      ],
      parameters: {
          treeAnnotationProperties : {
              hierarchyLevelFor : 'HIERARCHY_LEVEL',
              hierarchyNodeFor : 'ROW_ID',
              hierarchyParentNodeFor : 'PARENT_ROW_ID',
              hierarchyDrillStateFor : 'DRILL_STATE'
          }
      }
}">

你怎么看?有什么办法吗?

据我所知,XML 过滤器不支持来自 JSON/OData 模型的值。 您只能使用常量或其他方式,您可以在匹配的路由上的 JavaScript 控制器中实现它。

您必须使用绑定到视图的控制器。

你可以在onInit函数中写一些小逻辑。

onInit: function () {
  var table = this.byId("yourTableName");
  // get the value you want to use (not sure where and how your 
  // model is loaded)
  var value = this.getView().getModel().getParameter("yourParameter");
   
  // Bind your items here, use whatever you need and insert your filter value
  // Sorters etc can be added here
  table.bindItems({
    path: '/Model2',
    filters: [
      {
          path: 'LOC_ID',
          operator: 'EQ',
          value1: value
      }
    ],
    template: this.byId("tableTemplate"),
    templateShareable: true,
    parameters: {
      //your parameters
    }
  });
}

为了使其正常工作,请更改您的 XML。

<Table ...>
  <columns>
    ...
  </columns>
  < ! - - Your items need to be swapped out for dependents - - >
  <dependents>
    <ColumnListItem
      id="tableTemplate">
      ...
    </ColumnListItem>
  </dependents>
</Table>

所有这些都适用于 sap.m.Table - 但这应该适用于您的情况。