相关疑难解决方法(0)

在select2 multiselect中加载值

我用来select2代替搜索框.

在这里我用来加载像这样的国家值

$("#countries").select2({
    multiple: true,
    tags:["India", "Japan", "Australia","Singapore"],
    tokenSeparators: [","]
});
Run Code Online (Sandbox Code Playgroud)

当我按下保存按钮时,它们被正确地提交给服务器,现在这里的问题是当我想在保存到服务器后修改国家字段时,我如何将保存的值加载到国家/地区字段.

这是我从服务器检索数据的方式

$.getJSON('/dataprovider?data=fetchCountriesForm', function(opts) {

    //the opts here contains the json values of the countries.

    //what code should be written here to load the values in $('#countries).select2();

    //user can add some more countries or can remove the previously added countries. 

}
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-select2

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1

jquery ×1

jquery-select2 ×1