Select2自定义meessage不起作用

时间:2016-06-21 10:04:31

标签: ruby-on-rails coffeescript jquery-select2 select2

我正在尝试创建一个链接,以便在找不到结果时创建新对象。我正在使用Rails 4.我已经包含了gem systemctl enable myservice ,在application.js中添加了gem "select2-rails"并且

//= require select2
在application.js中

。这是我的coffeescript应该可以正常工作(ajax运行良好)但函数*= require select2 *= require select2-bootstrap 似乎什么都不做。

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 } )} ,但在很多用户示例中,它用于做同样的事情like here.

修改

根本不显示链接或自定义文字。

1 个答案:

答案 0 :(得分:1)

我环顾四周,发现这种方式可以在4.0+版本中完成。

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

    escapeMarkup: (markup) ->
        return markup;

请告诉我这是否适合您!