2016-11-02 31 views
1

我有一個充當搜索字段的輸入元素。下面的函數在提交搜索後針對範圍的數據過濾用戶輸入。如何使用過濾器「EQ」方法找到搜索字段的結果?

我的問題是:如何找到篩選結果?例如,假設用戶輸入了一個有效的產品,但數據中沒有顯示它的歷史記錄 - 如果提交的查詢結果與來自用戶的匹配項沒有匹配,我希望能夠通知用戶的方式(即:警報)數據?

onFilterProduct : function (oEvent) { 
     // build filter array 
     var aFilter = [], 
      //get the searchfield Id 
      oInput = this.byId("productSearch"), 

      oTable = this.getView().byId("idProductsTable"), 
      oBinding = oTable.getBinding("items"), 

      //get searchfield value 
      sQuery = oInput.getValue(), 

    if (sQuery) { 

      //push matches into aFilter array     
      aFilter.push(new Filter("Product", FilterOperator.EQ, sQuery)); 

      oBinding.filter(aFilter); 
     }; 
    }; 

我不知道哪裏可以在'aFilter'數組中找到它。

下面是一個例子,如果這將有助於 http://jsbin.com/vigeg/1/edit?js,output

回答

1

您可以使用oBinding.getLength()得到在應用列表中的過濾器後綁定條目的數量。在你的情況下,0將被返回。另一種方法是在應用過濾器後調用oTable.getItems(),它將返回一個空數組。