У меня есть следующий javascript, который представляет собой реализацию раскрывающегося списка со списком подражателей, он в основном похож на автозаполнение, но я добавил кнопку, и в обработчике события click у меня возникают трудности с выяснением, что именно записывать,Требование кнопки состоит в том, чтобы вывести прокручиваемый список всех элементов в базе данных, если входные данные для поиска пусты, в противном случае для вывода результата поиска в соответствующий поисковый запрос любая помощь подойдет .... большое спасибо!:
$(document).ready(function(){
$('input[data-ddcombobox]').railsCombobox();
});
(function( jQuery ){
var self = null;
$.fn.railsCombobox = function() {
return this.live('focus', function(){
if(!this.railsAutoCompleter){
this.railsAutoCompleter = new jQuery.railsCombobox(this);
}
});
};
jQuery.railsCombobox = function(e){
_e = e;
this.init(_e);
};
jQuery.railsCombobox.fn = jQuery.railsCombobox.prototype = {
railsCombobox: '0.0.1'
};
jQuery.railsCombobox.fn.extend = jQuery.railsCombobox.extend = jQuery.extend;
jQuery.railsCombobox.fn.extend({
init: function(e){
e.delimiter = $(e).attr('data-delimiter') || null;
function split( val ){
return val.split( e.delimiter );
}
function extractLast( term ) {
return split( term ).pop().replace(/^\s+/,"");
}
$(e).autocomplete({
source: function( request, response){
$.getJSON( $(e).attr('data-ddcombobox'), {
term: extractLast(request.term)
}, response );
},
search: function(){
// cusom minLength
var term = extractLast(this.value);
if(term.length < 2){
return false;
}
},
focus: function(){
// prevent value inserted on focus
return false;
},
select: function( event, ui ){
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma and space at the end
if(e.delimiter != null){
term.push("");
this.value = terms.join(e.delimiter);
}else{
this.value = terms.join("");
if($(this).attr('id_element')){
$($(this).attr('id_element')).val(ui.item.id);
}
};
return false;
}
});
////////////
this.button = $( "<button type='button'> </button>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.insertAfter(e)
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "ui-corner-right ui-button-icon" )
.click(function() {
// close if already visible
$(e).autocomplete("search", "");
});
////////////
}
});
})( jQuery );