嗨,我正在使用ajax autocomplete for jquery
插件
http://www.devbridge.com/projects/autocomplete/jquery/
有一个代码
function Autocomplete(el, options) {
this.el = $(el);
this.id = options.id;
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.fnFormatResult = fnFormatResult();
this.options = {
autoSubmit: false,
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
width: 0,
highlight: true,
params: {},
fnFormatResult: fnFormatResult,
delimiter: null,
zIndex: 9999
};
this.initialize();
this.setOptions(options);
}
在那里
this.options = {
autoSubmit: false,
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
width: 0,
highlight: true,
params: {},
fnFormatResult: fnFormatResult,
delimiter: null,
zIndex: 9999
};
它定义了一个函数来格式化结果
fnFormatResult: fnFormatResult,
我想使用 fnFormatResult
以外的函数,例如 fnFormatResult2
。
我想根据传递给插件的参数更改调用函数
我需要这样做
if(param == 1){
fnFormatResult: fnFormatResult,
}
else if(param == 1){
fnFormatResult: fnFormatResult2,
}
我怎样才能做到这一点。请帮忙......................
最佳答案
嗯,我想你可以这样做:
this.options = {
autoSubmit: false,
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
width: 0,
highlight: true,
params: {},
fnFormatResult: function(value, data, currentValue) {
if(param==1) {
return fnFormatResult.call(this, value, data, currentValue);
} else if (param==2) {
return fnFormatResult2.call(this, value, data, currentValue);
}
},
delimiter: null,
zIndex: 9999
};
关于javascript - 如何在 jquery 的 ajax 自动完成中编辑此代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7268206/