1

我将 Select2 与动态 ajax 加载/过滤一起使用。

我想要的是一个文本字段,就像您可以在此处的“多值选择框”下看到的那样:http: //ivaynberg.github.io/select2/

但我得到的只是一个下拉菜单。这是我的代码的一部分:

= f.input_field :community, :class => :communities

$(".communities").select2({
  allowClear:true,
  ajax: {
      ...
  },
  formatResult: formatResult,
  formatSelection: formatResult
});

我该怎么做才能获得文本字段而不是下拉菜单?

4

2 回答 2

1

I think createSearchChoice is the function you need.

read more at select2 search for createSearchChoice

$(".communities").select2({
 createSearchChoice(term)

});
于 2014-04-04T12:33:12.413 回答
0

你可以试试这个:

$('.communities').select2({
   width: '100%',
   allowClear: true,
   multiple: true, 
   ajax: {
     ...
   },   
});
于 2016-06-28T12:15:10.450 回答