2012-12-12 66 views
1

我正在使用jQueryUI的自動完成功能。它正確列出項目,我可以從列表中進行選擇。我遇到的問題是如何獲取來自源事件中使用的數組的所選項目的索引。如何獲取自動完成中選定項目的索引?

var options = { 
    select: function() { 
     // problem is here, I'm not able to see the correct index number of the selected item and always say -1 
     alert($.inArray($("#searchAText").val()), arrayA); 
    }, 
    source: function(req, response) { 
     var re = $.ui.autocomplete.escapeRegex(reg, term); 
     var matcher = new RegExp("^" + re + "i"); 
     response($.grep(arrayA, function(item, index) { 
      return matcher.test(item); 
     })); 
    } 
}; 
} 

回答

2

試試這個:

select: function(event, ui) { 
    alert($.inArray(ui.item.value, arrayA)); 
} 
+0

@Yetimwork Beyene見我的編輯,我敢肯定,這就是你要找的人。 – ParPar

+0

availableTags有什麼作用? –

+0

謝謝ParPar,您的解決方案完美無缺。再次感謝 –

相關問題