当未找到结果时,我试图创建一个创建新对象的链接。我使用的是Rails 4。我包含了gem gem "select2-rails",在application.js中添加了//= require select2,并且
*= require select2
*= require select2-bootstrap在application.js中。这里是我的coffeescript,它应该工作得很好(ajax工作得很好),但是函数formatNoMatches似乎什么也不做。
$('#invoice_client_id').select2
theme: 'bootstrap'
formatNoMatches: (term) ->
return "<a href='#' onclick='alert('" + term + "');'" + "id='newClient'>Add New Client</a>";
ajax:
url: '/clients.json'
dataType: 'json'
processResults: (data) ->
return {
results: $.map(data, (client, i) ->
{
id: client.id
text: client.name
}
)}我在文档中发现没有提到formatNoMatches,但是在很多用户示例中,它都用来做同样的事情-- like here.
编辑
链接或自定义文本根本不出现。
发布于 2016-06-24 09:47:42
我环顾四周,在4.0+版本中找到了这样的方法。
$('select').select2
language:
noResults: ->
return "<a href='http://google.com'>Add</a>";
escapeMarkup: (markup) ->
return markup;如果这对你有用,请告诉我!
https://stackoverflow.com/questions/37941397
复制相似问题