2

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

1 に答える 1

4

これを試して:

select: function(event, ui) {
     alert($.inArray(ui.item.value, arrayA));
}
于 2012-12-12T12:40:37.210 に答える