使用下拉列表过滤数据? [英] filter data using dropdown?
问题描述
我有都只是项目对象的数组。我也有,我想用它来允许用户通过价格或评级然而在页面加载应该没有过滤功能,一个下拉。
I have an array of objects which are just items. I also have a dropdown which I would like to use to allow the user to filter by price or rating however on page load there should be no filtering.
我如何项数据映射根据当前选择选项来过滤?
How do I map item data to filter based on the current select option?
我有一个plunkr上手:链接
I have a plunkr to get started: LINK
推荐答案
首先,你的选择值是模糊的。它们含有可以过滤和排序条目值 - 二者分开,因为它们是两个不同的功能。
First and foremost, your select values are ambiguous. They contain values that can filter AND sort the entries - Separate the two since they are two different functionality.
接下来,需要定义一个自定义过滤器,过滤器会根据所选的评级数据。对于这一点,你提高了过滤条件的等级属性评级值来选择评级相关联。
Next, you need to define a custom Filter which will filter the data based on the rating selected. For this, you enhance the filtering criteria with the "Rating" property to associate the rating selected with a rating value.
最后,关联与predicate和反向值分拣 - 的predicate确定(你的情况价)属性/列以确定排序而反向确定上升/下降的性质排序。
Finally, associate the sorting with a predicate and a reverse value - the predicate determines the property / column to determine for the sort (price in your case) while the reverse determines the ascending / descending nature of the sort.
整个code可以在这里找到 - http://plnkr.co/edit/n7TebC p = preVIEW
The entire code can be found here - http://plnkr.co/edit/n7TebC?p=preview
我已经更新了plunkr并介绍了注释,所以让我知道如果你不明白一个code。
I have updated the plunkr and introduced comments so let me know if you do not understand a code.
这篇关于使用下拉列表过滤数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!