我正在使用 jquery-select2 (4.0.0)。问题是当我选择一个选项,然后选择另一个选项时,item.selected对于两个选项都保持正确 - 永远。是否有一些我缺少的初始配置选项或者这是一个错误?
function formatResult(item) {
console.log("item selected = ", item.selected);
return item.text;
}
$('select').select2({
templateResult: formatResult,
minimumResultsForSearch: Infinity,
placeholder: "Please choose",
multiple: false,
maximumSelectionSize: 1
});
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.js"></script>
<select>
<option></option>
<option>conan</option>
<option>kimmel</option>
<option>stewart</option>
<option>colbert</option>
</select>