0

現在、jQuery API の使用に問題があります。

テキストボックスリスト

私が欲しいのは、Json配列形式で選択された値にアクセスすることです.今、ドキュメントは使用することを提案しています:

$('#form_tags_input').textboxlist();

しかし、ボタンクリックのjQuery関数で使用して[getValues]メソッドを使用して値を取得すると、未定義と表示されました。

ここにJavaScriptがあります:

<script type="text/javascript">

$(function () {
    // Standard initialization
    var t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
    //t.addEvent('bitBoxAdd', ContactAdded);
    //t.addEvent('bitBoxRemove', ContactRemoved);
    t.getContainer().addClass('textboxlist-loading');
    $.ajax({
        url: '/Home/GetContacts',
        dataType: 'json',
        success: function (r) {
            t.plugins['autocomplete'].setValues(r);
            t.getContainer().removeClass('textboxlist-loading');
        }
    });

});

function GetValues() {
    var tblist = $('#SentTo').textboxlist();
    alert(tblist.getValues());        
    return false;
}

function ContactAdded(e) {
    //alert(e);
    //GetValues();
    return false;
}

function ContactRemoved(e) {
    //alert(e);
}

ボタンクリックで GetValues() 関数を使用して値を取得しています。

助けていただければ幸いです。

ありがとう。

4

1 に答える 1

0

TextboxLists の "t" 変数をグローバルにしてみる

変更されたコードは次のとおりです。

$(function () {
    // Standard initialization
    t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
    //t.addEvent('bitBoxAdd', ContactAdded);
    //t.addEvent('bitBoxRemove', ContactRemoved);
    t.getContainer().addClass('textboxlist-loading');
    $.ajax({
        url: '/Home/GetContacts',
        dataType: 'json',
        success: function (r) {
            t.plugins['autocomplete'].setValues(r);
            t.getContainer().removeClass('textboxlist-loading');
        }
    });

});

function GetValues() {
    alert(t.getValues());        
    return false;

}
于 2012-08-01T11:51:10.133 に答える