问题
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
});
回答1:
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.
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'
}
}">
Then in Controller, filter Products
by their supplier country:
new Filter({
path: "ToSupplier/Country",
operator: "EQ",
value1: "UK",
})
(From: https://embed.plnkr.co/wAlrHB/).
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.
来源:https://stackoverflow.com/questions/48115183/filter-expanded-odata-request