添加额外的< li>标记到rails3-jquery-autocomplete插件的末尾 [英] Add a additional <li> tag to the end of rails3-jquery-autocomplete plugin

查看:61
本文介绍了添加额外的< li>标记到rails3-jquery-autocomplete插件的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自动完成列表的末尾添加一个附加标签.

I'm trying to add an addition tag to the end of the autocomplete list.

$('#address ul.ui-autocomplete').append("<li>Add Venue</li>");

我试图找出可以在上面放置代码的位置,以便将多余的li添加到自动完成列表中.

I'm trying to figure out where I can place the code above to add the extra li to the autocomplete list.

任何帮助将不胜感激.

这是rails3-jquery-autocomplete文件.

This is the rails3-jquery-autocomplete file.

  source: function( request, response ) {
  $.getJSON( $(e).attr('data-autocomplete'), {
    term: extractLast( request.term )
  }, function() {
    $(arguments[0]).each(function(i, el) {
      var obj = {};
      obj[el.id] = el;
      $(e).data(obj);
    });
    response.apply(null, arguments);
  });
},

open: function() {
  // when appending the result list to another element, we need to cancel the "position: relative;" css.
 if (append_to){
   $(append_to + ' ul.ui-autocomplete').css('position', 'static');

  } 
},
search: function() {
  // custom minLength

  var minLength = $(e).attr('min_length') || 2;
  var term = extractLast( this.value );
  if ( term.length < minLength ) {
    return false;
  }
},
focus: function() {
  // prevent value inserted on focus
  return false;
},
select: function( event, ui ) {
  var terms = split( this.value );
  // remove the current input
  terms.pop();
  // add the selected item
  terms.push( ui.item.value );

  // add placeholder to get the comma-and-space at the end
  if (e.delimiter != null) {
    terms.push( "" );
    this.value = terms.join( e.delimiter );
  } else {
    this.value = terms.join("");
    if ($(this).attr('data-id-element')) {
      $($(this).attr('data-id-element')).val(ui.item.id);

    }
    if ($(this).attr('data-update-elements')) {
      var data = $(this).data(ui.item.id.toString());
      var update_elements = $.parseJSON($(this).attr("data-update-elements"));
      for (var key in update_elements) {
        $(update_elements[key]).val(data[key]);
      }
    }
  }
  var remember_string = this.value;
  $(this).bind('keyup.clearId', function(){
    if($(this).val().trim() != remember_string.trim()){
      $($(this).attr('data-id-element')).val("");
      $(this).unbind('keyup.clearId');
    }
  });
  $(this).trigger('railsAutocomplete.select');
  return false;


}

}); }

推荐答案

解决了这个问题.

$('#address').bind('autocompleteopen', function(event,data){

$('<li id="ac-add-venue"><a href="....">Add venue</a></li>').appendTo('ul.ui-autocomplete');

});

这篇关于添加额外的&lt; li&gt;标记到rails3-jquery-autocomplete插件的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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