我正在尝试使用奇妙的方式以编程方式清除下拉菜单Select2 http://ivaynberg.github.com/select2/图书馆。使用 Select2 远程 ajax 调用动态填充下拉列表query
option.
HTML:
<input id="remote" type="hidden" data-placeholder="Choose Something" />
JavaScript:
var $remote = $('#remote');
$remote.select2({
allowClear: true,
minimumInputLength: 2,
query: function(options){
$.ajax({
dataType: 'json',
url: myURL + options.term,
error: function(jqXHR, textStatus, errorThrown){
smoke.alert(textStatus + ": server returned error on parsing arguments starting with " + options.term);
},
success: function(data, textStatus, jqXHR){
var results = [];
for(var i = 0; i < data.length; ++i){
results.push({id: data[i].id, text: data[i].name});
}
options.callback({results: results, more: false});
}
});
}
});
不幸的是,电话$remove.select2('val', '')
抛出以下异常:
Uncaught Error: cannot call val() if initSelection() is not defined
我尝试过设置attr
,设置val
, text
和 Select2 具体data
功能。似乎无法让这个人清楚地以单选按钮的方式工作。有人有建议吗?