Created
April 29, 2020 22:39
-
-
Save jackbillstrom/809ad8c2ee54c103f45ed4cf1f54d755 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filtered_boats: function () { | |
let filtered = this.boats; | |
// the minimums | |
let mins = { | |
"minPrice": 'price', | |
"minLength": 'length', | |
... | |
}; | |
filtered = Object.keys(mins).forEach(k => if (this.filter.options[k] !== null) filtered = filtered.filter(boat => boat[mins[k]] >= this.filter.options[k])); | |
// the maximums | |
let maxs = { | |
"maxPrice": 'price', | |
"maxLength": 'length', | |
... | |
}; | |
filtered = Object.keys(maxs).forEach(k => if (this.filter.options[k] !== null) filtered = filtered.filter(boat => boat[maxs[k]] <= this.filter.options[k])); | |
// the multi-value filters | |
let fields = ['brand', 'model', 'type', ...]; | |
filtered = fields.forEach(f => if (this.filter.options[f].length > 0) filtered = filtered.filter(boat => this.filter.options[f].indexOf(boat[f]) != -1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment