【发布时间】:2025-12-18 22:00:01
【问题描述】:
我使用select2 代替搜索框。
我在这里用来加载这样的国家/地区值
$("#countries").select2({
multiple: true,
tags:["India", "Japan", "Australia","Singapore"],
tokenSeparators: [","]
});
当我按下保存按钮时,它们已正确提交到服务器,现在问题是 当我想在保存到服务器后修改国家/地区字段时,如何将保存的值加载到国家/地区字段。
这就是我从服务器检索数据的方式
$.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.
}
【问题讨论】:
标签: javascript jquery jquery-select2