日期:2014-05-17  浏览次数:20931 次

求解:通过Jquery 动态绘制多行表格,应该如何向后台传递动态表格的value
query动态实现点击一个按钮添加一组元素,在像后台提交的时候应该如何处理,后台又应该如何接传递归来的value存到数据库,Jquery代码:
<script type="text/javascript">
$(document).ready(function(){
var spotMax = 10;
if($('div.spot').size() >= spotMax) {$(obj).hide();}
$("input#add").click(function(){     addSpot(this, spotMax);
});
});
function addSpot(obj, sm) {
$('div#spots').append(
    '<div class="spot">' +
'xx:    '+
'1:'+
    '<select name="item.vehi_type" ><option>测试</option></select> ' +
'2:'+
    '<select name="item.vehi_class" ><option>000</option></select> ' +
'3:'+
    '<input type="text" name="item.lice_no" /> ' +

'<br/>'+
    '<input type="button" class="remove" value="Delete" /></div>')
.find("input.remove").click(function(){
    $(this).parent().remove();
    $('input#add').show();
});
if($('div.spot').size() >= sm) {$(obj).hide();}
};
</script>
Action代码:
public ActionForward doAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
meetingForm myForm = (meetingForm)form ;

myForm.getItem1().setLhno(myForm.getItem().getLhno());
myForm.getItem1().setLhtime(myForm.getItem().getLhtime());
myForm.getItem1().setLhyear(myForm.getItem().getLhyear());
myForm.getItem1().setFlag(myForm.getItem().getFlag());
myForm.getItem1().setVehi_id(new findId().find("vehi_id", "unit_vehi_v"));
myForm.getItem().setMeetingid(new findId().find("meeting_id", "meeting"));

if(!this.shenpiBiz.add(myForm.getItem1())){
super.AddError("errors.user.allready_exists",myForm.getItem1().getName());
return mapping.findForward("add");
}
if (!this.meetingBiz.add(myForm.getItem())){
super.AddError("errors.user.allready_exists",myForm.getItem().getLhmc());

return mapping.findForward("add");
}

new tmp().updateCar(myForm.getItem1().getName(),new tmp().getCar(myForm.getItem1().getName()),new tmp().getVehi_type1(new tmp().getCar(myForm.getItem1().getName()), myForm.getItem1().getName()));

response.sendRedirect("meeting.do?o=toList");
return null;
}
原有需求是每次存入一组信息,要实现效果点击按钮添加多组信息后像后台发起请求,后台接受处理将多组信息存入数据库。

求大神详解。
Jquery 传递值 java

------解决方案--------------------
第一种方法,分别创建与页面对应类型的参数数组,比如页面有一个type='text'类型的input标签,name='test',那么就在后台创建一个数据,String[] test; 页面有多少类型的参数传递到后台,后台就创建几个数据,最后后台拼接对象的时候,遍历每个数组,然后获取所有数组的第N个元素拼接为第N个对象
第二种方法,直接创建一个对象数组,但是没测试过,不知道这样可行不可行。你可以试试。
------解决方案--------------------
可以使用json格式