我正在使用Ajax AutoComplete for jQuery
在我使用的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
的价值。有什么问题????
答案 0 :(得分:1)
嗯。我已经解决了。
我添加了额外的参数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