3
在我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) %>");
但是,如果以這種方式加載,select不起作用。爲什麼? 我需要重新初始化js嗎? 我在我的應用程序中不使用turbolinks
。
我知道這種方法,但我相信它不是最好的。 –
那麼,你可以使用'$(document).ajaxComplete'來代替文檔準備好,但是除了重新初始化之外,你別無選擇。 – ErvalhouS
我已經明白了這一點。這種方式不是很方便,但沒有其他辦法。 –