简体   繁体   English

用于获取Json数组的TextboxList问题

[英]TextboxList issue for getting Json array

I am currently having problem in using the jQuery API for 我目前在使用jQuery API时遇到问题

TextboxList 文字框清单

what i want is that to access the selected value in the Json array form, now the documentation suggest to use: 我想要的是访问Json数组形式中的选定值,现在该文档建议使用:

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

but when i use it in the jQuery function on button click to get values using [getValues] method it said undefined. 但是当我在按钮上的jQuery函数中使用它时,使用[getValues]方法获取值时它表示未定义。

here is the javascript: 这是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);
}

i am using GetValues() function on button click to getvalues. 我在单击按钮时使用GetValues()函数来获取值。

A help would be much appreciated. 一个帮助将不胜感激。

Thanks. 谢谢。

Try to made TextboxLists "t" variable global 尝试使TextboxLists“ t”变量成为全局变量

The changed code is: 更改后的代码为:

$(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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM