Select2 自定义消息不起作用

Select2 custom meessage doesn't work

我正在尝试创建一个 link 以在未找到任何结果时创建新对象。我正在使用 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.

编辑

Link 或自定义文本根本没有出现。

我环顾四周,发现在 4.0+ 版本中有这种做法。

$('select').select2
    language:
        noResults: ->
             return "<a href='http://google.com'>Add</a>";

    escapeMarkup: (markup) ->
        return markup;

让我知道这是否适合您!