I have a simple ArrayController in ember pre 1.0 and found that I can chop the list down if the filter finds an exact match for a given property, but what I can't seem to find is how do a "like" query with filter.
What I have below works if I search an array with users...
filtered = ['id', 'username'].map(function(property) {
return self.get('content').filterProperty(property, filter);
});
... and a few of the users have the same username. For example => if I search / filter by "smith" it will return both records as the "username" property has the exact match for "smith"
How can I change this map function to work with the like style query so when I type the word "sm" it still finds both of these records
Here is the jsfiddle showing the filter I show above in action http://jsfiddle.net/Rf3h8/
Thank you in advance
You can use a RegExp
object to test pieces of data for a match. Since you are writing your own filter logic, you'll have to use the filter
function. I've updated your fiddle to make this work: http://jsfiddle.net/Rf3h8/1/
Your fiddle contains a lot of code and may be hard for others to follow. Here is a very simple example of using RegExp
to filter an array.
var names = ['ryan', 'toran', 'steve', 'test'];
var regex = new RegExp('ry');
var filtered = names.filter(function(person) {
return regex.test(person);
});
filtered // => ['ryan']
In fact you could even refactor this to be
var filtered = names.filter(regex.test, regex);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With