2017-01-17 46 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"); 

应该解决问题。