我正在使用 select2 进行表单提交。我的 html 看起来像这样:
<%= form.select "page_request_ids", [], {}, id: "page_request_ids", multiple: true, style: "width:506px;" %>
javascript:
jQuery('select#page_request_ids').select2({
placeholder: "Start typing paths...",
allowClear: true,
ajax: {
url: "/page_requests/multiautocomplete",
dataType: 'json',
type: "GET",
data: function(params) {
return {
option: params.term,
};
},
processResults: function(data, params) {
return {
results: jQuery.map(data, function(item) {
return {
text: item[0] + " (" + item[1] + ")",
request: item[1],
id: item[2]
}
})
};
},
cache: true
}
});
当表单被提交时,这些值会清除表单字段。我试图确保在提交表单后出现这些值(提交表单时加载相同的表单)。
任何帮助都是极好的。