This question already has an answer here:
- Limit results in jQuery UI Autocomplete 9 answers
I've read all the questions in stackoverflow but i couldn't solve it.
I want To limit the show 1 result .
here's my Code :
Json
[
{
"label": "soheil", "category": "کانال" , "class":"channel", "url":"http://yahoo.com"
},
{
"label": "بانجیجامپینگ", "category": "کانال" , "class":"channel", "url":"http://google.com"
}
]
js :
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
},
_renderMenu: function( ul, items ) {
var that = this,
currentCategory = "";
$.each( items, function( index, item ) {
var li;
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
li = that._renderItemData( ul, item );
if ( item.category ) {
li.prepend("<span></span>")
li.attr( "aria-label", item.category + " : " + item.label);
li.attr("class", item.class);
}
});
}
});
var data = "/data.json";
$( "#search-input" ).catcomplete({
source:data,
select:function (event, ui) {
window.location.href = ui.item.url;
}
});
I want to show 1 result in maxmimum .
Any Advice ? Thanks
Aucun commentaire:
Enregistrer un commentaire