问题描述
在我加入 simple_form_for 之前,select2 工作得很好。现在浏览器控制台显示以下内容,我只看到呈现的常规输入字段:
<prosody rate="slow" contour="(5%,+40%) (10%,+20%) (15%,+10%) (40%,-10%) (60%,+20%) (100%,+30%)">Okay! To connect you with the best agent to speak with</prosody>
controllers/projects_controller.rb
[Error] Error: No select2/compat/inputData
callDep (application-216bdb7aa518f72cf379.js:29168)
req (application-216bdb7aa518f72cf379.js:29337)
(anonymous function) (application-216bdb7aa518f72cf379.js:29143)
Options (application-216bdb7aa518f72cf379.js:34179)
Select2 (application-216bdb7aa518f72cf379.js:34319)
(anonymous function) (application-216bdb7aa518f72cf379.js:34993)
each (application-216bdb7aa518f72cf379.js:7030)
(anonymous function) (application-216bdb7aa518f72cf379.js:34990)
initSelect2 (application-216bdb7aa518f72cf379.js:341)
(anonymous function) (application-216bdb7aa518f72cf379.js:164)
dispatchEvent
(anonymous function) (application-216bdb7aa518f72cf379.js:35348:1425)
(anonymous function) (application-216bdb7aa518f72cf379.js:35349:2793)
(anonymous function) (application-216bdb7aa518f72cf379.js:35349:1181)
(anonymous function) (application-216bdb7aa518f72cf379.js:35348:29997)
views/projects/new.html.erb
...
def new
@project = Project.new
@tags = ActsAsTaggableOn::Tag.pluck(:name).sort
end
...
/plugins/init_select2.js
<%= simple_form_for @project do |f| %>
<%= f.input :tag_list,label: 'Topics',input_html: { class: 'select2',multiple: 'multiple',data: { options: @tags,style: 'margin-bottom: 1rem;' } } %>
<% end %>
application.js
import $ from 'jquery';
import 'select2';
import 'select2/dist/css/select2.css';
const initSelect2 = () => {
$('.select2').select2({
width: 400,minimumInputLength: 2,maximumSelectionLength: 4,tags: $('.tags').data('options'),tokenSeparators: [',',' ']
});
};
export { initSelect2 };
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)