Reputation: 195
I'm "searching" (read filtering) some data with a input whos value is filtering an arrangedContent. Does anyone know/have an idea how I could highlight the letters being matched as I type?
I've included a JSBin to illustrate.
http://emberjs.jsbin.com/rojare/1/edit?html,js,output
Upvotes: 2
Views: 170
Reputation: 1264
I think the proper way to do this would be with an Handlebars helper
Ember.Handlebars.registerBoundHelper('highlight', function(value, options) {
var filter = options.hash.filter;
var regex = new RegExp(filter, "gi");
formattedTag = value.replace(regex, "<span class='highlight'>$&</span>");
return new Handlebars.SafeString(formattedTag);
});
To make the whole thing to work, I changed a bit the model and the template, check out my version of your jsbin : HERE
Upvotes: 1