我有一张桌子,每行都有一个“删除”按钮。我想要做的是将行id通过该按钮的onclick函数传递给控制器上的“删除”功能。
我的控制器
def studentDelete():
rec_id = request.args(0)
crud.delete(db.student, rec_id,next=URL('Home','Students_List'))
我的观点(当我点击按钮时,会显示一个模式来帮助用户确认或取消删除操作。#warning是模式中接受按钮的ID,如果用户决定删除记录的话。)
<div class='btn-group btn-group-justified JpositionA'><a class='btn btn-warning Jview btn-xs opciones'><span class='glyphicon glyphicon-remove'></span></a></div>;
<script>
$(document).on('click', '.opciones', function(e){
e.preventDefault();
btn = $(this);
var tr = $(this).closest('tr');
var row = tabla.row( tr );
var datos=row.data();
var id_record=datos.student.id;
$('#myModal').modal('show')
.one('click', '#warning', function(e) {
ajax('{{=URL('Tools', 'studentDelete')}}' + '?value=' + id_record);
});
});
});
</script>
Javascript代码将查询字符串中的记录ID作为value
变量发送到服务器,但Python代码期望request.args
中的ID。您只需将Python代码更改为:
rec_id = request.get_vars.value