我使用autosuggestion插件。如何防止onSelect在已選項目上觸發
首先我代碼:
$('.auto').autocomplete({
lookup: data,
onSelect: function (suggestion) {
console.log(koji);
$('#cena_'+koji).val(suggestion.cena);
console.log(suggestion.ID);
$('#jmere'+koji).val(suggestion.jmere);
$('#kol'+koji).val(suggestion.kol);
$('#popust'+koji).val(suggestion.popust);
$('#pdv'+koji).val(suggestion.porez);
etc...
,這是確定的,所以當我拿起從列表中的一些項目我更新其他輸入字段。
但之後我只是選擇#cena or #jmere
的其他值,但如果我再次點擊輸入字段與類.auto(之前選擇),然後onSelect再次啓動,我選擇手動#cena or #jmere
值更改爲建議的值。
請幫我解決這個問題。所以,我怎麼能阻止呼叫ONSELECT時已經回升項...
ONSELECT的JS代碼:
onSelect: function (index) {
var that = this,
onSelectCallback = that.options.onSelect,
suggestion = that.suggestions[index];
that.currentValue = that.getValue(suggestion.value);
if (that.currentValue !== that.el.val() && !that.options.preserveInput) {
that.el.val(that.currentValue);
}
that.signalHint(null);
that.suggestions = [];
that.selection = suggestion;
if ($.isFunction(onSelectCallback)) {
onSelectCallback.call(that.element, suggestion);
}
},
那麼,有沒有辦法改變ONSELECT選項 - 防止調用時,有已經選擇了一些項目?
僅供參考,'autocomplete'不是jQuery核心的一部分。我也添加了相關標籤(如果它真的是jquery-UI自動完成,您正在使用...嗎?) –
嘗試在項目預先解壓或取消綁定onSelect事件時刪除.auto類 – madalinivascu
否我使用devbridge autosuggestion插件,而不是jquery UI – MonkeyBusiness