0
我在使用select-2與我的Rails應用程序自動填充Ajax調用字段並允許多個值。如何在找不到匹配項時使用Select2動態添加新項目?
我CoffeScript文件:
$(document).ready ->
$('.select2').each (i, e) =>
select = $(e)
options =
placeholder: select.data('placeholder')
multiple: true
width: "100%"
maximumSelectionSize: 20
tokenSeparators: [",", " "]
dropdownClass: 'bigdrop'
if select.hasClass('ajax')
options.ajax =
url: select.data('source')
dataType: 'json'
data: (term, page) ->
q: term
page: page
per: 25
results: (data, page) ->
results: data.resources
more: data.total > (page * 25)
options.dropdownCssClass = "bigdrop"
select.select2(options)
我希望能夠到的情況下,增加新的項目沒有從服務器的結果,目前它不會讓我增加新項目(不保存在服務器並通過Ajax調用進行填充)。