- 列表项
我正在查看Jsfiddle网站上http://jsfiddle.net/g4stL/212/链接中的JQUERY示例。
我非常喜欢这个功能。事实上,我们需要在我们的应用程序中实现完全相同的功能。
如果我按原样复制代码,我可以看到多列自动完成。但是选择部分无法正常工作。如果我使用鼠标光标或箭头键进行选择,则程序会失败。
我收到的错误信息是:
"htmlfile: Unexpected call to method or property access."
这是在jQuery-1.7.2.js文件中的jQuery.fn.extend代码的附加函数中发生的错误。
mcautocomplete小部件位于MVC中脚本文件夹下的自定义js文件中。
你能帮忙吗?
$.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;
}
});
附加发现: 该代码在Fiddle中能够工作 该代码在Chorme或FireFox中不会崩溃。