[英]SAP UI5 Search - Binding to XML-View
我正在嘗試構建一個SAPUI5應用程序以顯示公司中的當前傳輸。 作為數據源,我們使用manifest.json中引用的SAP Backend-Service。
我的metadata.xml:
<EntityType Name="Transporteintrag" sap:content-version="1">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" sap:label="Zahl" sap:creatable="false" sap:updatable="false"/>
<Property Name="Land" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="Land" sap:creatable="false" sap:updatable="false"/>
<Property Name="Kunnr" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Warenempfänger" sap:creatable="false" sap:updatable="false"/>
<Property Name="Name1" Type="Edm.String" Nullable="false" MaxLength="30" sap:label="Name 1" sap:creatable="false" sap:updatable="false"/>
<Property Name="AnzMat" Type="Edm.Int32" Nullable="false" sap:label="Zahl" sap:creatable="false" sap:updatable="false"/>
<Property Name="Gesber" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Characterfeld der Länge 10" sap:creatable="false" sap:updatable="false"/>
<Property Name="Tknum" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Transportnummer" sap:creatable="false" sap:updatable="false"/>
</EntityType>
<EntityContainer Name="ZVERSAND_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="Transporteintrag_S" EntityType="ZVERSAND_SRV.Transporteintrag" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:searchable="true" sap:content-version="1"/>
<EntitySet Name="Transporteintrag_T" EntityType="ZVERSAND_SRV.Transporteintrag" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:searchable="true" sap:content-version="1"/>
<EntitySet Name="Transporteintrag_F" EntityType="ZVERSAND_SRV.Transporteintrag" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:searchable="true" sap:content-version="1"/>
<EntitySet Name="Transporteintrag_D" EntityType="ZVERSAND_SRV.Transporteintrag" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:searchable="true" sap:content-version="1"/>
</EntityContainer>
我通過使用XML和數據綁定與模型連接來構建視圖。
Page1.view.xml
<SearchField xmlns="sap.m" width="100%" placeholder="Suchen" id="__field0" liveChange="handleLiveSearch"/>
<Table id="Table_0_0" width="100%" noDataText="Das ist jetzt doof ..." mode="None" showSeparators="All" growing="true" growingThreshold="5000" growingScrollToLoad="true" items="{/Transporteintrag_D}">
<columns>
<Column hAlign="Left" vAlign="Top" minScreenWidth="Phone" demandPopin="true" popinDisplay="Inline" mergeDuplicates="false">
<header>
<Text text="WE" width="auto" maxLines="2" wrapping="true" textAlign="Begin" textDirection="Inherit" class="custom_font_table"/>
</header>
<footer/>
</Column>
</columns>
<items>
<ColumnListItem type="Active">
<cells>
<Text text="{= ${Name1}.substr(0,30)}" width="auto" maxLines="1" wrapping="false" textAlign="Begin" textDirection="Inherit" class="custom_font_table row_height"/>
</cells>
</ColumnListItem>
</items>
<headerToolbar>
<core:Fragment xmlns:core="sap.ui.core" fragmentName="Versand_Clean.view.TableHeaderFragment" type="XML" id="__toolbar_X0"/>
</headerToolbar>
</Table>
DataBinding
工作正常。 但是,在瀏覽器中打開應用程序時,所有數據都顯示在我的sap.m.table
。
為了給最終用戶更多的可用性,我正在嘗試實現一個實時搜索字段。
這是我的問題:我在Page1.controller.js中構建liveChange函數
handleLiveSearch: function (oEvent) {
var searchQuery = oEvent.getSource().getValue();
var oFilter = [new sap.ui.model.Filter("WE", sap.ui.model.FilterOperator.Contains, searchQuery)];
var oView = this.getView();
var oTable = oView.byId("Table_0_0");
var oBinding = oTable.getBinding("items");
if(searchQuery === "")
{
oBinding.filter( [] );
oBinding.refresh(true);
}
else
{
oBinding.filter(oFilter);
oBinding.refresh(true);
}
}
我的問題是通過在searchField中鍵入而發生的。 輸入第一個字符后,我的表未顯示任何數據。 當我清空搜索字段時,我的數據將再次顯示。
我的代碼有什么問題?
編輯:要檢查是否將過濾器應用於表格,我打開了Google Chrome開發者工具和標記源。 現在,我可以看到該過濾器已應用於表格。 但是表仍然沒有更新值。
該表中當前有3個值。 只有一個包含“ Delphi”。
問題在於過濾器您嘗試的屬性在元數據中不存在。
var oFilter = [new sap.ui.model.Filter("WE", sap.ui.model.FilterOperator.Contains, searchQuery)];
用Name1更改WE 。
var oFilter = [new sap.ui.model.Filter("Name1", sap.ui.model.FilterOperator.Contains, searchQuery)];
除了Saddamhussain的編輯之外,它還必須是:
oBinding.filter(oFilter, sap.ui.model.FilterType.Application);
這里的問題是包含運算符。 該運算符在SAP的OData實現中無法正常工作。 創建過濾器時,可以使用一些技巧並應用tolower
函數:
var searchQuery = searchQuery.toLowerCase();
// this step is important for the OData query
searchQuery = "'" + searchQuery + "'";
var filter = new sap.ui.model.Filter("tolower(Name1)", sap.ui.model.FilterOperator.Contains, searchQuery);
var oFilter = [ filter ];
另一方面,您可以使用另一個比較運算符,例如EQ
但是搜索字符串必須完全匹配:
var oFilter = [new sap.ui.model.Filter("Name1", sap.ui.model.FilterOperator.EQ, searchQuery)];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.