目前我所拥有的几乎正在发挥作用。 我正在使用以下内容:
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
发布评论