JQueryUI 1.10.0 Autocompleter renderItem问题 [英] JQueryUI 1.10.0 Autocompleter renderItem problems

查看:83
本文介绍了JQueryUI 1.10.0 Autocompleter renderItem问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了有关将'autocomplete'重命名为'ui-autocomplete'的解决方案(使用JQueryUI 1.10.0,JQuery 1.8.3),但仍然出现以下错误:

I tried a solution regarding renaming 'autocomplete' to 'ui-autocomplete' (using JQueryUI 1.10.0, JQuery 1.8.3) and am still getting an error for:

TypeError:$(...).autocomplete(...).data(...)未定义

TypeError: $(...).autocomplete(...).data(...) is undefined

} }).data('ui-autocomplete')._renderItem = function (ul, item) {

它在1.10.0中定义,但我需要重写:

its defined in 1.10.0 but I need to override:

_renderItem: function( ul, item ) {
return $( "<li>" )
.append( $( "<a>" ).text( item.label ) )
.appendTo( ul );
}, 

这是我的完整代码:

var ajaxCall_QuickSearchCompanyId;
            $('#QuickSearchCompanyId').autocomplete({
                minLength: 2, delay: 300, source: function (request, response) {
                    if (ajaxCall_QuickSearchCompanyId) {
                        ajaxCall_QuickSearchCompanyId.abort();
                    }
                    ajaxCall_QuickSearchCompanyId = $.ajax({
                        url: '/Advertiser/Autocompleter/CompaniesDetailed', dataType: 'json',
                        data: { q: request.term },
                        success:
                            function (data) {
                                $('#QuickSearchCompanyId').removeClass('ui-autocomplete-loading');
                                response($.map(data, function (item) {
                                    return {
                                        label: item.ID,
                                        value: item.Name,
                                        subsidiaries: item.Subsidiaries,
                                        category: item.Category,
                                        url: (item.URL == null) ? '' : item.URL,
                                        parentName: item.ParentName,
                                        isReported: item.IsReported
                                    }
                                }));
                            }
                    });
                }
            }).data('ui-autocomplete')._renderItem = function (ul, item) {
                String.prototype.chunk = function (n) {
                    var ret = []; for (var i = 0, len = this.length; i < len; i += n) { ret.push(this.substr(i, n)); }
                    return ret;
                }; ul.attr('id', 'ul_QuickSearchCompanyId'); return $('<li></li>')
                    .data('ui-autocomplete-item', item)
                    .append("<a style='padding: 0px;'><div style='margin-bottom: 0px; width: 450px;'><table style='height: 100%; width: 450px; font-family: Calibri; font-size: 10pt;'><tr><td style='width: 280px; border-right: solid 1px Black; padding: 0px; color: " + ((item.isReported != true) ? 'Gray' : 'Black') + "; font-style: " + ((item.isReported != true) ? 'italic' : 'none') + ";'>" + ((item.parentName != '[[root]]') ? (item.parentName + ': ') : '') + item.value + "</td><td align='right' valign='top' style='width: 150px; padding: 0px; color: " + ((item.isReported != true) ? 'Gray' : 'Black') + "; font-style: " + ((item.isReported != true) ? 'italic' : 'none') + ";'>" + item.category + "<br /></td></tr></table></div></a>")
                    .appendTo(ul);
            };

任何想法都会得到极大的应用.

Any Ideas would be greatly appriciated.

推荐答案

代替

$('selector').data('ui-autocomplete')._renderItem = function (ul, item) { };

您应该使用

$('selector').data('uiAutocomplete')._renderItem = function (ul, item) { };

这篇关于JQueryUI 1.10.0 Autocompleter renderItem问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆