Skip to content

Instantly share code, notes, and snippets.

@hunterbridges
Created February 25, 2012 00:11
Show Gist options
  • Save hunterbridges/1904787 to your computer and use it in GitHub Desktop.
Save hunterbridges/1904787 to your computer and use it in GitHub Desktop.
Command T style
filtered: function(q) {
q = q || this.query || '';
if (q === '') return this;
var chars = q.toLowerCase().replace(/[^0-9a-z]/,'').split('');
var searchFields = [
'order_number',
'vendor_name',
'product_name',
'redemption_shipping_label_tracking_number'
];
return _(this.filter(function (item) {
var include = false;
_(searchFields).each(function(f) {
var val = item.get(f) + '';
val = val.toLowerCase().replace(/[^0-9a-z]/,'');
if (!val) return;
var index = 0;
_(chars).each(function (c) {
if (index < 0) return;
index = val.indexOf(c, index);
});
if (index > -1) include = true;
});
return include;
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment