我添加了一个 select2,它总是将第一个选项显示为空白。在空白选项下方,它始终显示我在 select2 文本字段中输入的内容。任何想法,我该如何解决。
= hidden_field_tag :tags // 以 HAML 形式存在
// javascript
$('#tags').select2
createSearchChoice: (term, data) ->
if $(data).filter((->
@text.localeCompare(term) == 0
)).length == 0
return {
id: term
text: term
}
return
multiple: false
data: [
{
id: 0
text: 'story'
}
{
id: 1
text: 'bug'
}
{
id: 2
text: 'task'
}`enter code here`
]