只能选择一个学生,学生选择导师,可以选择多个导师。
先是一个学生数据表格,选择一行数据。点击选择导师。打开一个window出现导师的数据表格,可以多选,
然后按确定,学生表的数据库保存的导师的id:. 可以的到["18", "29", "32", remove: function, removeById: function] ,然后就不懂了。。 我要怎么把得到的ids传给数据库里的学生表?要不要重新写个action 或者做个更新学生表的teacherid的SQL语句。?要怎么
点击window的确定时,获取选中教师的id和学生datagrid选中的记录的id用ajax一起发送到数据库保存起来
var t=$('#teachergrid').datagrid('getSelections'),s=$('#studentgrid').datagrid('getSelected');
var tids=$(t).map(function(){return this.教师id列}).get().join(),sid=s.学生id列;
$.ajax({url:'xxx.jsp',data:{tids:tids,sid:sid},type:'POST',comlete:function(xhr){
if(xhr.responseText=='1'){
alert('保存成功!');
$('#windowid').window('close');
}else alert('更新有问题,服务器返回:'+xhr.responseText);
}})
xxx.jsp
String tids=request.getParameter("tids");
String sid=request.getParameter("sid");
'....你的入库或更新代码,最后输出1表示成功什么的
var test = $('#add_teacher').datagrid('getSelections');
var tids=$(test).map(function(){return this.id}).get().join(),sid=s.id;
console.log("学生"+sid+"老师"+tids);//学生21老师18,28
$.ajax({
url:basepath+'/youth/upt.do?id=sid',
data:{teacherId:tids,id:sid},
type:'POST',
comlete:function(xhr){
if(xhr.responseText=='1'){
alert('保存成功!');
$('#windowid').window('close');
}else alert('更新有问题,服务器返回:'+xhr.responseText);
}})
** Action:**
public void upt(){
try {
BaseDao dao = getDao();
dao.updateSql("youth.upt_youth", model);
this.setData("更新学生成功");
this.setSuccess(true);
this.send();
} catch (Exception e) {
e.printStackTrace();
this.setData("更新学生失败,错误信息:"+e.getMessage());
this.setSuccess(false);
this.send();
}
}
**sql**
<update id="upt_youth" parameterClass="youth">
update ybc_youth
<dynamic prepend="set">
<isNotNull property="name" prepend=",">name=#name#</isNotNull>
<isNotNull property="sex" prepend=",">sex=#sex#</isNotNull>
<isNotNull property="teacherId" prepend=",">teacherId=#teacherId#</isNotNull>
</dynamic>
where id=#id#
</update>