I am probably overlooking something or just being a noob but, I am having trouble being able to pass key-value pairs to a javascript function.
I am writing a filter module utilizing a Backbone.View and Backbone.Paginator.clientPager collection. I added a function to the clientPager called whereExpanded() which searches the entire collection without modifying/rendering anything.
Backbone.Paginator.clientPager.prototype.whereExpanded = function(attrs) {
return _.filter(this.origModels, function(model) {
var key;
for (key in attrs) {
if (attrs[key] !== model.get(key)) {
return false;
}
});
};
As you can see, it takes the attrs
variable and loops over it. I want to be able to pass in key value pairs to this but, the key and value need to be dynamic.
collection.whereExpanded(filterByField, filterByValue)
filterByField
is the attribute of the Backbone.Model I wish to filter by and filterByValue
is the value of the attribute I want to filter. I have tried utilizing eval()
but I cannot seem to get that to work either.
Any help woudl be greatly appreciated!