json データソースを使用するこの大幅に変更された json jQueryUI コンボボックスが、期待どおりに _renderMenu を起動しない理由を解明したいと思います。全体の目安は?- フッターに「カウント」を提供したいだけです。現在のディスプレイでは、多くのアイテムが存在しないという「錯覚」を与えていると思うからです。
$.widget("ui.combobox", {
options:{
dataSource: "",
dataType: "",
updateId: "custom_combobox_realvalue"
},
_create: function() {
var self = this,
select = this.element.hide(),
selected = select.children(":selected"),
value = selected.val() ? selected.text() : "";
var input = this.input = $("<input>").insertAfter(select).val(value).autocomplete({
delay: 0,
minLength: 0,
source: function(request, response) {
$.ajax({
url: self.options.dataSource,
type: "POST",
dataType: self.options.dataType,
data: {
maxRows: 12,
term: request.term
},
success: function(data) {
response($.map(data.params, function(item) {
return {
label: item.name,
name: item.name,
id: item.id
}
}));
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
})
},
//selected index
select: function(event, ui) {
//debugger;
$('#' + self.options.updateId).val(ui.item.id);
},
}).addClass("ui-widget ui-widget-content ui-corner-left");
input.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.name + "</a>").appendTo(ul);
};
this.button = $("<button type='button'> </button>").attr("tabIndex", -1).attr("title", "Show All Items").insertAfter(input).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
if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return;
}
// work around a bug (likely same cause as #5265)
$(this).blur();
// pass empty string as value to search for, displaying all results
console.log($(this));
console.log(input);
//debugger;
input.autocomplete("search", input.val());
input.focus();
});
},
_renderMenu: function( ul, items ) {
///this bit never shows
alert("this _renderMenu call alter box never fires");
var self = this;
$.each( items, function( index, item ) {
if (index == 0)
ul.append( '<li><input type="checkbox"> I\'m at the top! Choose me!</li>' );
self._renderItem( ul, item );
if(index == items.length - 1)
ul.append( '<li><input type="checkbox"> I\'m at the bottom! Choose me!</li>' );
});
},
destroy: function() {
this.input.remove();
this.button.remove();
this.element.show();
$.Widget.prototype.destroy.call(this);
}
});
現時点ではステップスルーしていますが、なぜ _renderMenu がコンボボックスで機能しないのかわかりませんが、バニラのオートコンプリートでは機能します。