不会触发Jquery UI多列自动完成更改事件

时间:2013-12-13 15:00:31

标签: jquery-ui autocomplete custom-formatting

我正在使用jquery-ui自动完成与多列使用 _renderMenu _renderItem jsfiddle

$.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;
}
});

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

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

提前致谢

1 个答案:

答案 0 :(得分: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);

Here is a working jsfiddle using jquery 1.10

相关问题