Reputation: 7659
i am trying to use jquery autocomplete component.i want to show images in autocomplete.so i have to write _renderMenu and _renderIItem function.i wrote a code :
var _filterUser = $('#filterUser').autocomplete({
source: onEditLoadUsers,
select: onEditSelectUser,
focus: onEditFocusUser
});
$('#filterUser').data("autocomplete")._renderItem= function( ul, item ){
console.log('coming here');
return $( "<li>" )
.append( $( '<img src="'+item.photo+'" />' ) )
.appendTo( ul );
};
$('#filterUser').data("autocomplete")._renderMenu= function(ul,items){
var that = this;
console.log('ul is')
console.log(ul);
console.log(items);
$.each( items, function( index, item ) {
that._renderItemData( ul, item );
});
};
if i remove _renderItem function and _renderMenu function then simple autocomplete is working but when i add these two function it gave me error :
Uncaught TypeError: undefined is not a function FullCalendar?sfdc.tabName=01ri0000000sqRT:359
(anonymous function) FullCalendar?sfdc.tabName=01ri0000000sqRT:359
v.extend.each jquery.min.js:2
$.data._renderMenu FullCalendar?sfdc.tabName=01ri0000000sqRT:358
a.widget._suggest jquery-ui.min.js:5
a.widget.__response jquery-ui.min.js:5
(anonymous function) jquery-ui.min.js:5
onEditLoadUsers FullCalendar?sfdc.tabName=01ri0000000sqRT:779
a.widget._search jquery-ui.min.js:5
a.widget.search jquery-ui.min.js:5
(anonymous function)
i am using jquery 1.8.3 and jquery UI 1.8 .Please guideline how to resolve this error ??
Upvotes: 0
Views: 9061
Reputation: 454
You can not extend the object in such a way.
Try this way:
(function ($, undefined) {
var ac = $.ui.autocomplete.prototype;
if (typeof $.uix !== "object") { $.uix = {}; }
ac = $.extend({}, ac, {
_renderItem: function (ul, item) {
console.log('coming here');
return $("<li>")
.append($('<img src="' + item.photo + '" />'))
.appendTo(ul);
},
_renderMenu: function (ul, items) {
var that = this;
console.log('ul is')
console.log(ul);
console.log(items);
$.each(items, function (index, item) {
that._renderItemData(ul, item);
});
}
});
$.uix.autocomplete = ac;
$.widget("uix.autocomplete", $.uix.autocomplete);
})(jQuery);
Upvotes: 1