我有一个充当搜索字段的输入元素。下面的函数在用户提交搜索后根据范围数据过滤用户输入。
我的问题是:如何找到过滤结果?例如,假设用户输入了有效的产品,但数据没有显示它的历史记录 - 我希望有一种方法,如果提交的查询结果与搜索结果不匹配,我可以通知用户(即:警报)数据?
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
最佳答案
应用过滤器后,您可以使用oBinding.getLength()
获取列表绑定(bind)中的条目数。在你的情况下,将返回 0。另一种方法是在应用过滤器后调用 oTable.getItems()
,它将返回一个空数组。
关于javascript - 如何使用 Filter "EQ"方法查找搜索字段的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40386620/