如何通过骨干中的多个选择选项进行筛选(How to filter by multiple select options in backbone)

编程入门 行业动态 更新时间:2024-10-24 16:28:00
如何通过骨干中的多个选择选项进行筛选(How to filter by multiple select options in backbone)

目前我所拥有的几乎正在发挥作用。 我正在使用以下内容:

this.collection.reset(jobArray, {silent: true}); var filterDepartment = this.filterDepartment; var filterCategory = this.filterCategory; var filterLocation = this.filterLocation; var filteredResult = this.collection.where({ department: filterDepartment, category: filterCategory, location: filterLocation }); this.collection.reset(filteredResult);

如果我选择部门,类别和位置,这很有用。 但是,如果我希望它仅按部门+位置过滤,将类别保留为默认的“全部”值,则应在所有类别中返回过滤/选定的部门和位置。 此外,如果我选择一个类别,然后选择“全部”,那么它应该只按位置搜索。

我有办法做到这一点,但它是很多代码,肯定有一个更简单的方法?

Currently what I have is almost working. I'm using the following:

this.collection.reset(jobArray, {silent: true}); var filterDepartment = this.filterDepartment; var filterCategory = this.filterCategory; var filterLocation = this.filterLocation; var filteredResult = this.collection.where({ department: filterDepartment, category: filterCategory, location: filterLocation }); this.collection.reset(filteredResult);

This works great if I select a department, a category, and a location. However, if I want it to only filter by department + location, leaving category as the default 'all' value, it should return the filtered/ selected department and location, within all categories. Furthermore, if I select a category, then select "all" instead, it should then only be searching by location.

I have a way to do this but it is a LOT of code, surely there is an easier way?

最满意答案

怎么样

this.collection.reset(jobArray, {silent: true}); var filterDepartment = this.filterDepartment; var filterCategory = this.filterCategory; var filterLocation = this.filterLocation; var filter = {}; if (filterDepartment) filter['department'] = filterDepartment if (filterCategory) filter['category'] = filterCategory; if (filterLocation) filter['location'] = filterLocation; console.log(filter); // Dump the filter var filteredResult = this.collection.where(filter); this.collection.reset(filteredResult);

How about

this.collection.reset(jobArray, {silent: true}); var filterDepartment = this.filterDepartment; var filterCategory = this.filterCategory; var filterLocation = this.filterLocation; var filter = {}; if (filterDepartment) filter['department'] = filterDepartment if (filterCategory) filter['category'] = filterCategory; if (filterLocation) filter['location'] = filterLocation; console.log(filter); // Dump the filter var filteredResult = this.collection.where(filter); this.collection.reset(filteredResult);

更多推荐

collection,location,department,reset,电脑培训,计算机培训,IT培训"/> <meta nam

本文发布于:2023-07-15 05:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110637.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   骨干   选项   filter   backbone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!