2013-12-13 47 views
0

我使用jQuery UI的使用_renderMenu_renderItem与列自动完成按jsfiddlejQuery 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; 
} 
}); 

改变,如果我点击自动完成之外没有被触发事件选择任何结果。

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

在此先感谢

+0

难道ÿ你曾经解决过这个问题吗?我有完全一样的。它似乎ui.item:未定义。另外,正如你可以从这个[jsfiddle](http://jsfiddle.net/8CFL4/)看到的,它不能在jQuery UI 1.10中工作,但[工作](http://jsfiddle.net/g4stL/212/ )在jquery 1.8.18中 –

回答

0

我设法解决这个问题,jQuery的改变由自动完成从“item.autocomplete”的项目数据保存到“用户界面,自动完成项目”,因此解决方法是改变你的关键行:

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

相关问题