我有一个对象数组,它们只是项目。我还有一个下拉列表,我想用它来允许用户按价格或评级进行过滤,但是在页面加载时应该没有过滤。
如何根据当前选择选项将项目数据映射到过滤器?
我有一个 plunkr 开始:链接
我有一个对象数组,它们只是项目。我还有一个下拉列表,我想用它来允许用户按价格或评级进行过滤,但是在页面加载时应该没有过滤。
如何根据当前选择选项将项目数据映射到过滤器?
我有一个 plunkr 开始:链接
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.
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.
The entire code can be found here - http://plnkr.co/edit/n7TebC?p=preview
I have updated the plunkr and introduced comments so let me know if you do not understand a code.