如何在 Ajax AutoComplete 中为 jQuery 传递额外参数?

发布于 2024-11-29 22:47:14 字数 2474 浏览 1 评论 0原文

你好,我在我的jquery中使用Ajax AutoComplete for jQuery

,我正在使用

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

我看到我可以传递额外的参数,

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'
            });

我如何从自动完成代码访问该额外参数?我想将该 id 添加到我的

.autocomplete-w1

初始位置,它看起来像这样,

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

我想更改它以

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

请帮助........................................ ...

更新

我尝试将我的 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' 我通过 jquery2 没有得到的值。那里有什么问题???

hi i am using Ajax AutoComplete for jQuery

in my jquery i am using

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

i saw that i can pass extra parameters like

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 
  });

so i want to create n new parameter and pass it like this

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

How can i access that extra parameter from the autocomplete code ?? i want to add that id to my

.autocomplete-w1

initially it looks like this

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

i want to change it to

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

please help................................

UPDATE

i tried to adding my id parameter to this function

  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);
  }

i gave a default value test . when i alert $this.options.id i always getting 'test' the value i passig jquery2 is not getting . what is the problem there ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-12-06 22:47:14

嗯。我已经解决了。

添加了额外的参数 id,

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

我在我的 jquery.autocomplete.js

 function Autocomplete(el, options) {

一样,

  this.id = options.id;

就像现在我可以将它添加到 div 的 id 中

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

谢谢...... ....:) :) :D

hmmm. i have solved it .

i added extra parameter id

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

in my jquery.autocomplete.js in

 function Autocomplete(el, options) {

i get that parameter like

  this.id = options.id;

now i can add it to div's id

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

thanks.................... :) :) :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文