datagrid 同时绑定多个事件

提问 未结 1 5043
悬赏:20飞吻
datagrid 绑定多个事件现在的写法是如下:
现在想问的是,都执行同一种方法,是不是有更简单的写法?

data-options="id:'userDg',
rownumbers: true,
singleSelect:false,
url:_ctx+'ashx/Json_View_SJ_fontuser.aspx',
onCheck:function(index,row){
//1. 获取用户选中的所有值
var rows = $('#userDg').iDatagrid('getChecked');

//2. 遍历rows
var val = '';
var uid='';
$.each(rows,function(index){
val += rows[index].turename;
val = rows.length == (index+1) ? val: val+',';
uid += rows[index].uuid;
uid = rows.length == (index+1) ? uid: uid+',';
});

//3. 给用户输入框赋值
$('#m_truename').val(val);
$('#m_userid').val(uid);
},onCheckAll:function(index,row){
//1. 获取用户选中的所有值
var rows = $('#userDg').iDatagrid('getChecked');

//2. 遍历rows
var val = '';
var uid='';
$.each(rows,function(index){
val += rows[index].turename;
val = rows.length == (index+1) ? val: val+',';
uid += rows[index].uuid;
uid = rows.length == (index+1) ? uid: uid+',';
});

//3. 给用户输入框赋值
$('#m_truename').val(val);
$('#m_userid').val(uid);
},onUncheckAll:function(index,row){
//1. 获取用户选中的所有值
var rows = $('#userDg').iDatagrid('getChecked');

//2. 遍历rows
var val = '';
var uid='';
$.each(rows,function(index){
val += rows[index].turename;
val = rows.length == (index+1) ? val: val+',';
uid += rows[index].uuid;
uid = rows.length == (index+1) ? uid: uid+',';
});

//3. 给用户输入框赋值
$('#m_truename').val(val);
$('#m_userid').val(uid);
},onUncheck:function(index,row){
//1. 获取用户选中的所有值
var rows = $('#userDg').iDatagrid('getChecked');

//2. 遍历rows
var val = '';
var uid='';
$.each(rows,function(index){
val += rows[index].turename;
val = rows.length == (index+1) ? val: val+',';
uid += rows[index].uuid;
uid = rows.length == (index+1) ? uid: uid+',';
});

//3. 给用户输入框赋值
$('#m_truename').val(val);
$('#m_userid').val(uid);
}
"
回帖
回帖须知