Created
July 27, 2013 17:30
-
-
Save atatos/6095595 to your computer and use it in GitHub Desktop.
this is an example of the autocomplete jQuery ui ( JSON & Bold hightlighted)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#search-txt").autocomplete({ | |
source: function (req, responseFn) { | |
$.ajax({ | |
url: "/search.json", | |
dataType: "json", | |
success: function(data) { | |
var re = $.ui.autocomplete.escapeRegex(req.term); | |
var matcher = new RegExp( "^" + re, "i" ); | |
var a = $.grep( data, function(item,index){ | |
return matcher.test(item.value); | |
}); | |
responseFn( a ); | |
}, | |
error: function (error) { | |
} | |
}); | |
} | |
}).data('ui-autocomplete')._renderItem = function( ul, item) { | |
var re = new RegExp("^" + this.term, "i") ; | |
var t = item.value.replace(re,"<span style='font-weight:600;'>" + this.term + "</span>"); | |
return $( "<li></li>" ) | |
.data( "item.autocomplete", item ) | |
.append( "<a>" + t + "</a>" ) | |
.appendTo( ul ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment