在new对象之前先做需要数据的选择。以下是一个实现方法。 <% form_for(@cad_active) do |f| %> <input type="hidden" id= "stu_reg_infids" name= "stu_reg_infids" > <!--用来js接收form_remote_tag中的多选框数据--> <% form_remote_tag :url=>{:controller=>'active_search_stu'},:update=>'stus_all' do -%> <table width="100%" class="edit view search"> <%=render :partial =>"/stu_reg_infs/find" %><!--其中含有查找的button--> </table> <table width="100%" border="0" class="list view" id="stus_all"> <!--返回一个带form_remote_tag的partial支持再次查找更新stus_all 其中带有多选框active[stu_reg_inf_ids]、和button、还有传递已有数据stu_reg_inf_ids(字符串集)的hidden。--> </table> <% end %> <%= button_to_function "保存", "check_feedback(this)" %> <% end %> <script type="text/javascript"> function check_feedback(form){ var chkStatus1 = document.getElementsByName("active[stu_reg_inf_ids][]"); for (i = 0; i < chkStatus1.length; i++) { if (chkStatus1[i].checked==true){ document.getElementById('stu_reg_infids').value=document.getElementById('stu_reg_infids').value+","+chkStatus1[i].value } } document.forms[1].submit(); return true; } </script> CONTROLLER: def active_search_stu cad_students_search#多条件查询方法,返回查询结果集。 @stu_reg_inf_ids=[] if params[:stu_reg_inf_ids]&¶ms[:stu_reg_inf_ids]!=[]#上次搜索的记录 @students_ids=[] students_ids=params[:stu_reg_inf_ids].split(",") for students_id in students_ids student_id=students_id.to_i if student_id>0 @students_ids<<students_id end end for stu_reg_inf in @stu_reg_infs if @students_ids.include?stu_reg_inf.id.to_s#查询记录已包含本次查询的某一对象 @students_ids.delete stu_reg_inf.id.to_s#删除上次记录保留本次记录 end end @studentsids=[] if params[:active] if params[:active][:stu_reg_inf_ids] for stu_reg_inf_id in @students_ids if params[:active][:stu_reg_inf_ids].include?(stu_reg_inf_id.to_s)#上次查询 对象出现在本次打对勾的集体当中 @studentsids<<stu_reg_inf_id end end @students_ids=@studentsids#新的赋值 end else#此次提交为空 @students_ids=[]#从数组中删除,清空数组 end if @students_ids!=[] for stu_reg_inf_id in @students_ids @stu_reg_inf_ids<<stu_reg_inf_id stu_reg_inf=StuRegInf.find(stu_reg_inf_id) @stu_reg_infs<<stu_reg_inf end end @stu_reg_infs = @stu_reg_infs.paginate( :page => params[:page],:per_page =>100, :order =>'convert(created_at using gbk)desc',:order => 'convert(name using gbk)') end for stu_reg_inf in @stu_reg_infss#本次搜索记录 @stu_reg_inf_ids<<stu_reg_inf.id end @stu_reg_infids="" for stu_reg_inf_id in @stu_reg_inf_ids @stu_reg_infids=@stu_reg_infids+","+stu_reg_inf_id.to_s end render :partial=>"/stu_reg_infs/search" end
详细解决方案
form中嵌套form可以透过js指定具体form提交
热度:148 发布时间:2012-12-27 10:17:10.0
相关解决方案
- 求jquery.form.js+jquery.validate.min.js 用ajax提交表单的代码范例
- 关于<form action >的一个有关问题
- jquery form 有关问题
- form 表单交付 <form action="<c:url value='desktop'/>"
- ENCTYPE="multipart/form-data"文件下传有关问题
- form.getForm.submit对象不支持此属性或步骤
- jsp中<form>标记有关问题?头疼了很多天
- 关于enctype="multipart/form-data"及过滤器的怪异有关问题~
- import form.addBookForm 有晓得这个包的出处的嘛?SOS~
- Windows Form 中怎么将 treeview 的节点与页面内容关联
- Form.FormClosing事件不触发(winform)解决思路
- postbackurl 和 <form action="">中的action有什么区别解决方法
- 求问大家html submit表单后一些控件为什么在服务端request.form.allkeys里取不到呢解决方案
- asp.net 的 form post 哪里去了?解决方法
- Request.Form 的
- Form Control在IE中使用的有关问题
- form 之间传值,该如何解决
- 第 1 行: 'form' 附近有语法异常
- Request.Form[4]的疑问?解决方法
- 怎样把Html文本转换为System.Windows.Form.HtmlDocment对象解决思路
- 关于'form' 附近有语法异常(待)
- 关于Profile,Form,Cookies如何使用?多谢
- 怎么在</form>之前写javascript脚本
- 关于asp.net request.form 的有关问题
- 请教大家都是把<form runat="server">放在母板页里还是放在内容页里?那种方式好?
- form 认证 cookie 永久保留有关问题
- 有哪位高手知道Page.Request.Form.Set()的用法?
- Request.Form["DropDownList5"].ToString()这句话是什么意思
- MOSS 2007中InfoPath Form Template 不能下传
- createobject("form")创建表单怎么保存