is it possible to use variables with .where in _.js?
I am making a filtering system that gets an array of objects and filters out the selected objects on click. However, the objects to be filtered are different based on the elements chosen, so I would like to use _.js to filter variables passed to it with _.where
Hardcoded values work perfectly, but when replaced with replica variables, it shoots out a blank array.
var user_filters = user_array;
var filtered_text;
$('.allFilters li').click(function () {
var $this = $(this);
var selected_filter = $this.siblings('a').text();
selected_filter = selected_filter.toLowerCase();
var filters = $this.attr('data-filter-value');
filters = '"'+filters+'"';
selected_filter = selected_filter;
console.log(selected_filter, filters);
user_filters = _.where(user_filters, {selected_filter: filters});
console.log (user_filters);
});
filters = '"'+filters+'"';. Additional can you create a JSFiddle?filters, and might be causing trouble. I doubt this method is not working because you're using variables.testis a literal, butselectedisn't. The notation is exactly the same. If you're going to say becauseselectedis a variable, how would you then be able to use the literal stringselectedas a key?