Skip to content

Instantly share code, notes, and snippets.

@karlbright
Last active August 29, 2015 14:00
Show Gist options
  • Save karlbright/11243315 to your computer and use it in GitHub Desktop.
Save karlbright/11243315 to your computer and use it in GitHub Desktop.
$('#search').keyup(function () {
var searchField = $('#search').val();
var regExp = new RegExp(searchField, 'i');
$.getJSON('data.json', function (data) {
var results = [];
var output = $('<ul>').addClass('output');
var results = $.map(data, function(value, key) {
var match = value.name.search(regExp);
return match === -1 ? value : null;
});
if(!results) output.append('<li>No results found</li>');
$.each(results, function(index, result) {
var result = $('<li>');
result.text(result.name);
result.attr('href','#');
output.append(result);
});
$('#results').html(output);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment