相关疑难解决方法(0)

无法使用HTML设置未定义的jQuery UI自动完成的属性'_renderItem'

我正在使用以下代码将我的jQuery UI自动完成项呈现为HTML.这些项在自动完成控件中正确呈现,但我一直收到此javascript错误,无法移动它.

Firefox 无法转换JavaScript参数

Chrome 无法设置未定义的属性"_renderItem"

  donor.GetFriends(function (response) {
    // setup message to friends search autocomplete
    all_friends = [];
    if (response) {
        for (var i = 0; i < response.all.length - 1; i++) {                
                all_friends.push({
                    "label":"<img style='padding-top: 5px; width: 46px; height: 46px;' src='/uploads/profile-pictures/" +
                        response.all[i].image + "'/><br/><strong style='margin-left: 55px; margin-top: -40px; float:left;'>" +
                        response.all[i].firstname + " " + response.all[i].lastname + "</strong>",

                    "value":response.all[i].firstname + " " + response.all[i].lastname,
                    "id":response.all[i].user_id});
            }
        }        

    $('#msg-to').autocomplete({
        source:all_friends,
        select:function (event, ui) {               
            // set the id …
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-ui jquery-autocomplete

68
推荐指数
5
解决办法
6万
查看次数

使用_renderItem类中断自动完成字段

我有一个jQuery自动完成字段,到目前为止一直工作正常.我决定使用_renderItem它,因为我想在结果中使用一些HTML.这是我的代码:

function prepareClientField() {

  var renderItemFunction = function(ul, item) {
    return $("<li></li>")
      .data("item.autocomplete", item)
      .append(item.label)
      .appendTo(ul);
  };

  $("#client_name").autocomplete({
    source: clientNames,
    delay: 0
  }).data("autocomplete")._renderItem = renderItemFunction;

  $("#client_name").focus();
}
Run Code Online (Sandbox Code Playgroud)

因为现在,我无法在自动填充字段中使用向上/向下箭头.我甚至无法使用鼠标单击结果中的项目.还有什么我需要做才能让它真正起作用吗?

jquery autocomplete

5
推荐指数
1
解决办法
2676
查看次数

jQuery自动完成给出TypeError:this._renderItem(...)未定义

我目前.data( "ui-autocomplete" )._renderItem = function( ul, item )在我的页面中的三个地方使用.现在我需要再添加一个,我已经完成了.

但是这次我得到了错误信息

TypeError:this._renderItem(...)未定义

奇怪的是,如果我的IF测试是假的,我只会得到这个.

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

  // If only one row is returned and ID = 0, then return 'no result' message
  if(item.id == '0') {
    return jQuery( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<div class='no-result'>"+ item.value + "</div>" )
        .appendTo( ul );
  }
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么它在这里失败了,而不是在其他3个地方.某处有冲突吗?

这是我的代码

jQuery('#my-selector').autocomplete({
  minLength: 2,
  source: function( request, response ) {
    jQuery.ajax({
        url: callback_url,
        dataType: "json",
        data: …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui-autocomplete

1
推荐指数
1
解决办法
9538
查看次数