<script type="text/javascript">
$('.search').autocomplete({
delay: 500,
minLength: 3,
source: function(request, response) {
$.getJSON('/rest.json', { q: request.term }, function(result) {
response($.map(result, function(item) {
return {label:item.label, searchLink:item.searchLink};
}));
});
},
select:function(e,ui) { location.href = ui.item.searchLink; }
});
</script>
使用此代码.autocomplete工作有些奇怪:它显示来自json数据的所有行。 Json内容:
[{"label":"link to find 1", "searchLink":"http://blala.xom"},
{"label":"link to find 2", "searchLink":"http://blala.xom"},
{"label":"link to find 3", "searchLink":"http://blala.xom"}]
结果是下一个: ResultImage