0

我使用_renderMenu_renderItem按照jsfiddle使用带有多列的 jquery-ui 自动完成

$.widget('custom.mcautocomplete', $.ui.autocomplete, {
_renderMenu: function(ul, items) {
    var self = this,
        thead;

    if (this.options.showHeader) {
        table = $('<div class="ui-widget-header" style="width:100%"></div>');
        $.each(this.options.columns, function(index, item) {
            table.append('<span style="padding:0 4px;float:left;width:' + item.width + ';">' + item.name + '</span>');
        });
        table.append('<div style="clear: both;"></div>');
        ul.append(table);
    }
    $.each(items, function(index, item) {
        self._renderItem(ul, item);
    });
},
_renderItem: function(ul, item) {
    var t = '',
        result = '';

    $.each(this.options.columns, function(index, column) {
        t += '<span style="padding:0 4px;float:left;width:' + column.width + ';">' + item[column.valueField ? column.valueField : index] + '</span>'
    });

    result = $('<li></li>').data('item.autocomplete', item).append('<a class="mcacAnchor">' + t + '<div style="clear: both;"></div></a>').appendTo(ul);
    return result;
}
});

如果我在自动完成之外单击而不选择任何结果,则会触发更改事件。

但是单击标题(列)然后单击外部时不会触发更改事件。

提前致谢

4

1 回答 1

0

我设法解决了这个问题,jquery 更改了自动完成将项目数据从“item.autocomplete”保存为“ui-autocomplete-item”的键,因此解决方法是更改​​您的行:

result = $('<li></li>').data('item.autocomplete', item).append('<a class="mcacAnchor">' + t + '<div style="clear: both;"></div></a>').appendTo(ul);

result = $('<li></li>').data('ui-autocomplete-item', item).append('<a class="mcacAnchor">' + t + '<div style="clear: both;"></div></a>').appendTo(ul);

这是一个使用 jquery 1.10 的工作 jsfiddle

于 2014-02-12T16:15:51.950 回答