在我的
在我的应用程序的另一个部分,我有一个带有
作为响应,它会加载局部文件:
application.js
文件中,我有 .select2
选择器的初始化设置:$(document).ready(function() {
$(".select2").select2({
theme: "bootstrap",
width: '100%',
allowClear: true
});
});
在我的应用程序的另一个部分,我有一个带有
remote: true
链接,它将呈现一个带有 .select2
的下拉列表的新表单。<%= link_to 'new form' new_feed_item_path, class: 'new-feed-item', remote: true %>
作为响应,它会加载局部文件:
new.js.erb
。$('.feed-content').html("<%= j(render 'form', feed_item: @feed_item) %>");
但是如果以这种方式加载,选择器无法工作。为什么?
我需要重新初始化js吗?
我在我的应用程序中没有使用turbolinks
。
$(document).ajaxComplete
替代 document ready,但你别无选择只能重新初始化它。 - ErvalhouS