2017-01-17 43 views
-1

使用以下代碼的過濾器不起作用。我使用Web IDE中的模板創建了一個應用程序,然後將OData綁定到XMLView中的列表中,在搜索上應用過濾器。在UI5中過濾數據

查看:

<SearchField liveChange="onSearch" id="master1SearchField" search="onSearch"/> 
<List id="master1List" items="{path:'/DetailsSet'}"> 
    <items> 
     <ObjectListItem id="master1ListItem"> 
      <attributes> 
       <ObjectAttribute text="{Name}"/>        
      </attributes> 
     </ObjectListItem> 
    </items> 
</List> 

控制器:

onSearch : function(oEvent) { 
    var sFilteredValue = oEvent.getSource().getValue(); 
    var oFilter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, sFilteredValue); 
    var oElement = this.getView().byId("table"); 
    var oBinding = oElement.getBinding("items"); 
    oBinding.filter([oFilter]);    
} 
+0

如果切換到調試模式,您應該在網絡選項卡中看到過濾器請求到後端及其響應。 這是否工作?它看起來怎樣? 如果你在調試器,什麼是「sFilteredValue」這裏的價值: 「 VAR sFilteredValue = oEvent.getSource()的getValue();」 請也比較樣本編碼中: https://開頭sapui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.ListSelectionSearch/code/List.controller.js –

+0

您是否在正確的控件上應用了過濾器? 「oElement」的ID是「table」,而列表的ID是「master1List」。 – boghyon

+0

這裏返回什麼? 'var sFilteredValue = oEvent.getSource()。getValue();' – neeko

回答

-1

試圖強行控制的更新設置過濾器後:

oBinding.refresh(true); 
+0

這不會提供問題的答案,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你將能夠[評論任何帖子](http:// stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](http://meta.stackexchange.com/questions/214173/why-do-i-need-50 - 信譽評論 - 什麼是我可以做 - ) - [來自評論](/評論/低質量 - 文章/ 15605204) – Robert

1

您需要獲得項目的結合需要在其上應用過濾器。

var oElement = this.getView().byId("master1List"); 

應該解決問題。