过滤扩展的 OData 请求 [英] Filter expanded OData request

查看:55
本文介绍了过滤扩展的 OData 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向后端传递一个参数.我想为此使用 $filter.我下面的代码不起作用,io_tech_request_context->get_filter()->get_filter_select_options()Figures 实体集中没有返回过滤器.

I need to pass a parameter to the backend. I want to use $filter for this. My code below is not working, there are no filters returned by io_tech_request_context->get_filter( )->get_filter_select_options( ) in the Figures entityset.

var aFilters = [ new sap.ui.model.Filter("TeamMembers/Figures/FILTERKEY", sap.ui.model.FilterOperator.EQ,   sFilterValue) ];

this.getView().bindElement({
    path: "/TeamDataSet('0')",
    parameters: {
     expand: 'TeamMembers/Figures'
    },
    filters: aFilters
});

推荐答案

元素绑定/ContextBinding 不支持 filters 属性,因为您只绑定单个实体而不是集合.如果您需要过滤Figures,您必须将它们绑定到一个聚合(例如List),得到对应的ListBinding 对象,然后调用.filter 从那里.

Element binding / ContextBinding doesn't support the property filters since you're binding just a single entity and not a collection. If you need to filter Figures, you'll have to bind them to an aggregation (e.g. items on List), get the corresponding ListBinding object, and then call .filter from there.

这是一个类似的例子:https://embed.plnkr.co/AoIZI4/.查看处理程序 onSearch.

Here is a similar example: https://embed.plnkr.co/AoIZI4/. Take a look at the handler onSearch.

如果有人真的想通过扩展结果过滤列表,可以在过滤器路径中应用导航属性,然后通过绑定绑定对象的路径解析.例如:

In case someone actually wants to filter a list by expanded results, the navigation property can be applied in the Filter path which then gets resolved by the path of the bound binding object. For example:

<List items="{
  path: 'myODataModel>/Products',
  parameters: {
    expand: 'ToSupplier'
  }
}"> 

然后在 Controller 中,按供应商所在国家/地区过滤 Products:

Then in Controller, filter Products by their supplier country:

new Filter({
  path: "ToSupplier/Country",
  operator: "EQ",
  value1: "UK",
})

(来自:https://embed.plnkr.co/wAlrHB/).

请注意,这仅在扩展不会不会导致集合而是单个对象(例如关联的供应商)时才有效.从 OData V4 开始支持通过查找关联的集合进行过滤,这可以通过 FilterOperator.All/.Any.

Be aware that this works only if expanding does not result in a collection but a single object (e.g. associated supplier). Filtering by looking up at an associated collection is supported as of OData V4 which can be achieved via FilterOperator.All / .Any.

这篇关于过滤扩展的 OData 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆