[英]Ruby On Rails: How to pass javascript variable to params hash?
I have a javascript array variable that is created in an action => new
form but I can't seem to find a way to return this variable as a field to the controller along with the other form field inputs. 我有一个在action => new
表单中创建的javascript数组变量,但是我似乎找不到找到将这个变量作为字段与其他表单字段输入一起返回给控制器的方法。 How do I set this array to a hidden field in the form. 如何将此数组设置为表单中的隐藏字段。 Is there a way to pass the array back into the parameters hash to the controller? 有没有一种方法可以将数组传递回参数哈希值到控制器?
$(document).ready(function() {
arr = new Array();
$(document).on('change', 'select[id ^="package"]', function() {
var arr = $('select[id ^="package"]').map(function(){
return this.value
})
});
});
I have this javascript array and I want to submit the form with :packages
set to the javascript variable arr
. 我有这个javascript数组,我想提交:packages
设置为javascript变量arr
的表单。
如果您已经有一个隐藏字段,则可以在JavaScript中执行此操作:
$('#MODELNAME_packages').val(arr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.