【发布时间】:2015-08-01 21:32:29
【问题描述】:
我的页面上有以下选择:
<select><option value="1" selected="selected">Caption</option></select>
我调用 select2 (v 4.0) init:
city.select2({
ajax: {
url: <...>,
data: <...>,
processResults: <...>,
cache: true
},
escapeMarkup: function(markup){ return markup; },
minimumInputLength: 0,
templateResult: function(repo){ return repo.name; },
templateSelection: function(repo){ return repo.name; }
});
问题是 select2 正在重置默认选定值并显示空白字符串。有没有办法在 select2 init 上设置默认值?
【问题讨论】:
-
我认为您可能想要使用 initSelection 选项。我没有手头的工作示例,但您可能想研究一下您的解决方案。
标签: javascript jquery ajax jquery-select2 jquery-select2-4