[英]Initialize multiple selections in select2
I'm developing a multiple selection in Select2 4.0 and Rails 4.2.7.1. 我正在Select2 4.0和Rails 4.2.7.1中开发多个选择。 The code saves the right value in the database, but I've noticed a problem: it loses all value selection after a failed validation. 该代码将正确的值保存在数据库中,但是我注意到一个问题:验证失败后,它将丢失所有的值选择。 How could i initialize all the value previously selected after a page reload? 重新加载页面后,如何初始化所有先前选择的值? Thanks. 谢谢。
This is the current select2 declaration: 这是当前的select2声明:
$(select_report).select2({
ajax: {
url: '/vaccination_plans/index_json',
dataType: 'json',
data: function (params) {
return {
q: params.term
};
},
processResults: function (data, params) {
return {
results: data
};
},
cache: true
},
templateResult: function (data) {
return data.vaccine_name;
},
templateSelection: function (data) {
return data.vaccine_name;
},
minimumInputLength: 3
});
Actually all that was necessary was set the values (selection_array) server-side, then call the select2 initialization 实际上,所有需要做的就是在服务器端设置值(selection_array),然后调用select2初始化
Es. Es。
<%= f.collection_select :attribute, selection_array, :id, :value, {}, {:class => 'form-control', :multiple => true} %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.