选择jquery - 列表未以模态形式加载
16lz
2021-01-22
In rails 4.2.2, I am using chosen
jquery plugin for dropdown(multiple) field inside a modal
form. Right now form & field is loading with no errors but collection(list) is not loading, if I try to search then it shows "No results...".
在rails 4.2.2中,我在模态表单中使用选择的jquery插件用于下拉(多个)字段。现在表单和字段正在加载没有错误但收集(列表)没有加载,如果我尝试搜索然后它显示“没有结果......”。
In controller,
@users = User.all.collect(&:name)
In views,
<%= f.input :users, :as =>:select, :label=>false, :collection =>[], :input_html=>{:multiple=>true, :class=>"form-control"} %>
In view.js.erb
var content = "<%= escape_javascript(render(:partial=>"form")) %>";
var container = $('#main-lightbox-container');
container.find('.modal-content').html(content);
container.modal({});
initializeMultipleChoose("#event_users", JSON.parse('<%= raw(@users) %>'), {width: "95%", max_selected_options: 5, allow_single_deselect: true});
$("#event_users").trigger("chosen:updated");
In custom .js file,
在自定义.js文件中,
function initializeMultipleChoose(id, selectedOptions, parameters){
selectedOptionsArray = $.isArray(selectedOptions) ? selectedOptions : [selectedOptions]
object = $(id);
$.each(object.find("option"), function(key, content){
option = object.find(content);
if(selectedOptionsArray.indexOf(option.val())> -1)
option.attr('selected',true);
})
object.chosen(parameters);
}
What I need to do for loading a list? Please help me.
我需要做什么才能加载列表?请帮我。
1 个解决方案
#1
0
Maybe the reason is that you are trying to init the chosen plugin BEFORE the HTML DOM is available? Could you check?
也许原因是你在HTML DOM可用之前尝试初始化所选的插件?你能检查一下吗?
更多相关文章
- 阻止用户在表单字段中输入
- CORS错误:请求标头字段预检响应中的Access-Control-Allow-Headers
- 如何在选择单选按钮时显示文本字段
- 将输入文本字段显示为纯文本
- 在用户将'n'粘贴复制到文本字段后,如何更新视图模型?
- 带有无线电的JavaScript条件字段不起作用
- 如何在onchange()事件后调用的方法中将焦点设置为输入字段?
- 无法在JQuery中查找表单输入
- 用于转换单位的HTML和JavaScript表单