Jquery autocomplete - custom html for result listing

前端 未结 4 1654
夕颜
夕颜 2020-12-24 12:59

I am referring to this plugin: http://jqueryui.com/demos/autocomplete/

So the original structure for the results is

4条回答
  •  轮回少年
    2020-12-24 13:36

    You can use create event for autocomplete for newer versions. Like this:

    create: function () {
                $(this).data('ui-autocomplete')._renderItem = function (ul, item) {
                    var path = 'basepath' + item.value;
                    return $('
  • ') .append('
    ') .append('') .append('') .append(item.label) .append('') .append('
    ') .append('
  • ') .appendTo(ul); // customize your HTML }; }

    For full code review, I am attaching the way I bound autocomplete to my textbox.

    $('.myTextBox').autocomplete({
            source: function (request, response) {
    
                // your call to the server
            },
            select: function (event, ui) {
                // when item is selected
                $(this).val(ui.item.label);
            },
            create: function () {
                $(this).data('ui-autocomplete')._renderItem = function (ul, item) {
                    var path = 'basepath' + item.value;
    
                     return $('
  • ') .append('
    ') .append('') .append('') .append(item.label) .append('') .append('
    ') .append('
  • ') .appendTo(ul); // customize your HTML }; } });

提交回复
热议问题