问题描述
我目前正在为我的公司开发一个 MasterDetail 应用程序,该应用程序提供以节点表示的可扩展类别.
节点及其子节点与导航属性的绑定不是问题.但是,如果我想在上面的搜索字段中搜索某个组节点,它只会在四个最高节点之间进行过滤.它可以搜索第一层的节点,但无法找到低于第一层的节点.
树的绑定:
/noDataText}";busyIndicatorDelay="{masterView>/delay}";项目={路径:'/GroupNodes',参数 : {展开:'ChildGroupNodes',导航: {'GroupNodes': 'ChildGroupNodes'}}}><标准树项标题={文本}"类型=导航"按=onSelectionChange"/></树>
onSearch:
onSearch: function(oEvent) {if (oEvent.getParameters().refreshButtonPressed) {this.onRefresh();返回;}var sQuery = oEvent.getParameter(查询");如果(查询){this._oListFilterState.aSearch = [new Filter(Stext", FilterOperator.Contains, sQuery)];} 别的 {this._oListFilterState.aSearch = [];}this._applyFilterSearch();},
_applyFilterSearch:
_applyFilterSearch: function() {var aFilters = this._oListFilterState.aSearch.concat(this._oListFilterState.aFilter),oViewModel = this.getModel();this._oList.getBinding("items").filter(aFilters, "Application");如果(aFilters.length !== 0){oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataWithFilterOrSearchText"));} else if (this._oListFilterState.aSearch.length > 0) {oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataText"));}},
onInit() 函数中的过滤状态:
this._oListFilterState = {过滤器:[],a搜索:[]};
元数据:
<钥匙><PropertyRef Name=Grpid"/></键><属性名称=Grpid"类型=Edm.String"可空=假"MaxLength=8"sap:unicode="false";sap:label="Id Trainingsgruppe";sap:creatable="false";树液:可更新=假";sap:filterable="false"/><属性名称=短"类型=Edm.String"MaxLength=12"sap:unicode="false";sap:label="Kürzel Trainingsgruppe";sap:creatable="false";树液:可更新=假";sap:sortable="false";sap:filterable="false"/><物业名称=Begda"类型=Edm.DateTime"精度=0"sap:unicode="false";sap:label="Beginndatum";sap:creatable="false";树液:可更新=假";sap:sortable="false";sap:filterable="false"/><属性名称=Endda"类型=Edm.DateTime"精度=0"sap:unicode="false";sap:label="Endedatum";sap:creatable="false";树液:可更新=假";sap:sortable="false";sap:filterable="false"/><属性名称=Parentid"类型=Edm.String"可空=假"MaxLength=8"sap:unicode="false";sap:label="ParentId"sap:creatable="false";树液:可更新=假";sap:filterable="false"/><NavigationProperty Name="ChildGroupNodes";关系=Z_HR_LSO_WORKCENTER_SRV.GroupNodeToParent"FromRole=FromRole_GroupNodeToParent"ToRole=ToRole_GroupNodeToParent"/><NavigationProperty Name="GroupToTrainingType";关系=Z_HR_LSO_WORKCENTER_SRV.GroupToTrainingType"FromRole=FromRole_GroupToTrainingType"ToRole=ToRole_GroupToTrainingType"/></实体类型>
我们正在使用 OData V2,因此不可能实现 FilterContains.All 过滤器.
前端是否可以过滤sap.m.Tree的子节点?
首先,通过
服务端
- 对于服务器端过滤,只有FilterType
Application"
和operationMode:Server"支持代码>.在这种情况下,服务器需要使用现成的树结构来响应
$filter
请求.这同样适用于兄弟节点和子节点的分页请求.
限制
suspended: true
尚未支持绑定信息中的 (问题 #3161).- 以上内容仅适用于OData V2.
V4 ODataModel 根本不支持树绑定(问题 #2728).
I'm currently working at a MasterDetail application for my company, which provides expandable categorys represented as nodes.
The binding of the nodes and it's child nodes with a navigation property isn't a problem. However, if I want to search for a certain group node in the search field above, it only filters between the four highest nodes. It can search for the nodes on the first level, but it isn't able to find nodes if they're below the first level.
Binding of the tree:
<Tree
selectionChange="onSelectionChange"
id="list"
noDataText="{masterView>/noDataText}"
busyIndicatorDelay="{masterView>/delay}"
items="{path: '/GroupNodes',
parameters : {
expand: 'ChildGroupNodes',
navigation: {
'GroupNodes': 'ChildGroupNodes'
}
}
}">
<StandardTreeItem
title="{Stext}"
type="Navigation"
press="onSelectionChange"/>
</Tree>
onSearch:
onSearch: function(oEvent) {
if (oEvent.getParameters().refreshButtonPressed) {
this.onRefresh();
return;
}
var sQuery = oEvent.getParameter("query");
if (sQuery) {
this._oListFilterState.aSearch = [new Filter("Stext", FilterOperator.Contains, sQuery)];
} else {
this._oListFilterState.aSearch = [];
}
this._applyFilterSearch();
},
_applyFilterSearch:
_applyFilterSearch: function() {
var aFilters = this._oListFilterState.aSearch.concat(this._oListFilterState.aFilter),
oViewModel = this.getModel();
this._oList.getBinding("items").filter(aFilters, "Application");
if (aFilters.length !== 0) {
oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataWithFilterOrSearchText"));
} else if (this._oListFilterState.aSearch.length > 0) {
oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataText"));
}
},
Filterstate in the onInit() function:
this._oListFilterState = {
aFilter: [],
aSearch: []
};
Metadata:
<EntityType Name="GroupNode" sap:content-version="1">
<Key>
<PropertyRef Name="Grpid"/>
</Key>
<Property Name="Grpid" Type="Edm.String" Nullable="false" MaxLength="8" sap:unicode="false" sap:label="Id Trainingsgruppe" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
<Property Name="Short" Type="Edm.String" MaxLength="12" sap:unicode="false" sap:label="Kürzel Trainingsgruppe" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Stext" Type="Edm.String" MaxLength="40" sap:unicode="false" sap:label="Bezeichnung Trainingsgruppe" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
<Property Name="Begda" Type="Edm.DateTime" Precision="0" sap:unicode="false" sap:label="Beginndatum" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Endda" Type="Edm.DateTime" Precision="0" sap:unicode="false" sap:label="Endedatum" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Level" Type="Edm.Int32" sap:unicode="false" sap:label="Level" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Parentid" Type="Edm.String" Nullable="false" MaxLength="8" sap:unicode="false" sap:label="ParentId" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
<NavigationProperty Name="ChildGroupNodes" Relationship="Z_HR_LSO_WORKCENTER_SRV.GroupNodeToParent" FromRole="FromRole_GroupNodeToParent" ToRole="ToRole_GroupNodeToParent"/>
<NavigationProperty Name="GroupToTrainingType" Relationship="Z_HR_LSO_WORKCENTER_SRV.GroupToTrainingType" FromRole="FromRole_GroupToTrainingType" ToRole="ToRole_GroupToTrainingType"/>
</EntityType>
We're working with OData V2, so there's no possibility to implement an FilterContains.All filter.
Is it even possible to filter through the child nodes of a sap.m.Tree in the front-end?
First of all, building the tree hierarchy via navigation
is deprecated since 1.44. Instead, SAP recommends to leverage metadata annotations:
Once the migration to the annotation approach is done, filter either client-side or server-side.
Client-side
The
operationMode
of the ODataTreeBinding (or thedefaultOperationMode
of the v2.ODataModel) needs to be"Client"
.When calling
.filter
, the FilterType as the 2nd argument needs to be"Control"
.Here is a working example: https://embed.plnkr.co/moTGOT
Server-side
- For server-side filtering, only the FilterType
"Application"
and theoperationMode: "Server"
are supported. In that case, the server needs to respond to the$filter
request with a ready-made tree structure. The same applies to paging requests for sibling and child nodes.
Limitations
suspended: true
in the binding info is not yet supported (Issue #3161).- The above content applies to OData V2 only.
V4 ODataModel doesn't support tree binding at all yet (Issue #2728).
这篇关于如何搜索 sap.m.Tree 中的所有节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!