关于jquery easyui treegrid的问题
我是用的django web开发架构;
想实现如下功能:
点击checkbox时,能获取该checkbox的值;
代码如下:
<tr>
<th field="name" width="160px">组织架构</th>
{% for cap in caps_list %}
<th field="{{ cap.rightname }}" width="100px" formatter='formatCheckbox'>{{ cap.rightname }}</th>
{% endfor %}
<th field='depid' hidden width="100px">部门ID</th>
<th field='uid' hidden width="100px">用户ID</th>
<th field='rightvalue' hidden width="100px">权限值</th>
<script>
function setvalue(value,id){
var ret = $(this).attr('checked') ? 1: 0;
alert(ret?'checked':'not checked');
$('#setcaps_usertree').treegrid('select',id);
var node = $('#setcaps_usertree').treegrid('getSelected');
var opts = $('#setcaps_usertree').treegrid('getColumnFields');
alert(opts);
if (ret){
$(this).attr('checked',false);
node.rightvalue -= value;
} else {
$(this).attr('checked',true);
node.rightvalue += value;
}
alert(node.rightvalue);
}
function formatCheckbox(value,rec){
//var id = $(this).attr('field');
//var index = $('#setcaps_usertree').treegrid('getRowIndex',rec);
var a = "<input type='checkbox' onclick='setvalue("+value+","+rec.id+");'/>";
//alert(a);
return a;
}
</script>
</tr>
目前,这个实现有点问题,就是所有field都共用一个input元素,导致每次取checkbox是否checked时,是累积的;预期的功能是:每个input元素只表示这个treegrid中的一列,而不是表示所有的列;
已经解决;
因为input的标识是name,所以为input元素加一个name属性,
function setvalue(value,id){
var ret = $('#rightcheckbox').attr('checked') ? 1: 0;
//alert(ret?'checked':'not checked');
$('#setcaps_usertree').treegrid('select',id);
var node = $('#setcaps_usertree').treegrid('getSelected');
var opts = $('#setcaps_usertree').treegrid('getColumnFields');
//alert(opts);
if (ret){
$(this).attr('checked',false);
node.rightvalue -= value;
} else {
$(this).attr('checked',true);
node.rightvalue += value;
}
alert(node.rightvalue);
}
function formatCheckbox(value,rec){
//var id = $(this).attr('field');
//var index = $('#setcaps_usertree').treegrid('getRowIndex',rec);
var a = "<input name='rightcheckbox' type='checkbox' onclick='setvalue("+value+","+rec.id+");'/>";
//alert(a);
return a;
}