2011-08-18 2 views
2

안녕하세요 전 jQueryjQuery를위한 Ajax AutoComplete에서 추가 매개 변수를 전달하는 방법?

내 jquery

  options = { serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete" };  
     a = $('#query').autocomplete(options); 

아약스 AutoComplete 사용하고 있습니다.

var a = $('#query').autocomplete({ 
    serviceUrl:'service/autocomplete.ashx', 
    minChars:2, 
    delimiter: /(,|;)\s*/, // regex or character 
    maxHeight:400, 
    width:300, 
    zIndex: 9999, 
    deferRequestBy: 0, //miliseconds 
    params: { country:'Yes' }, //aditional parameters 
    noCache: false, //default is false, set to true to disable caching 
    // callback function: 
    onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); }, 
    // local autosugest options: 
    lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values 
    }); 

그래서 여분의 매개 변수를 전달할 수있는 보았다 n 새로운 매개 변수를 만들려면 원하는 이걸

   var a = $('#query2').autocomplete({ 
      serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete", 
      id:'query2' 
      }); 

어떻게 자동 완성 코드에서 해당 추가 매개 변수에 액세스 할 수 있습니까 ?? 그

처음에

<div class="autocomplete-w1"></div> 

이 ID를 추가하려면

변경하십시오. 도와주세요 ........ ........................

업데이트

이 함수에 내 id 매개 변수를 추가하려고했습니다.

 function Autocomplete(el, options) { 
    this.el = $(el); 
    this.el.attr('autocomplete', 'off'); 
    this.suggestions = []; 
    this.data = []; 
    this.badQueries = []; 
    this.selectedIndex = -1; 
    this.currentValue = this.el.val(); 
    this.intervalId = 0; 
    this.cachedResponse = []; 
    this.onChangeInterval = null; 
    this.ignoreValueChange = false; 
    this.serviceUrl = options.serviceUrl; 
    this.isLocal = false; 
    this.options = { 
     autoSubmit: false, 
     minChars: 1, 
     maxHeight: 300, 
     deferRequestBy: 0, 
     width: 0, 
     highlight: true, 
     params: {}, 
     fnFormatResult: fnFormatResult, 
     delimiter: null, 
     zIndex: 9999, 
     id:'test' 
    }; 
    this.initialize(); 
    this.setOptions(options); 
    } 

나는 기본값 test을 주었다. 내가 $this.options.id에 경고 할 때 나는 항상 'test' 값을 얻는다. passig jquery2은 얻지 못한다. 거기에 무슨 문제가 있니?

답변

1

hmmm. 나는 그것을 해결했다. 내가

function Autocomplete(el, options) { 

jquery.autocomplete.js에 추가 매개 변수 아이디

 a = $('#query').autocomplete({ 
             serviceUrl: "<? echo $this->config->item('base_url'); ?>index.php/welcome/autocomplete", 
             id: 'query' 
            }); 

을 추가

내가

this.id = options.id; 

같은 해당 매개 변수가 지금은 DIV의 ID에 추가 할 수 있습니다 얻을

<div class="autocomplete-w1" id='+this.id+'></div> 

감사합니다 .................... :) :) : D

관련 문제