Jquery easyui 怎么得到datagrid 里面的值和传到后台

2023-07-25 20:04发布

var insertRows = $(#test).datagrid(getChanges,inserted);x0dx0a var updateRows

var insertRows = $(#test).datagrid(getChanges,inserted);x0dx0a var updateRows
1条回答
2023-07-25 20:42 .采纳回答
var insertRows = $('#test').datagrid('getChanges','inserted');\x0d\x0a var updateRows = $('#test').datagrid('getChanges','updated');\x0d\x0a var deleteRows = $('#test').datagrid('getChanges','deleted');\x0d\x0a var changesRows = {\x0d\x0a inserted : [],\x0d\x0a updated : [],\x0d\x0a deleted : [],\x0d\x0a };\x0d\x0a if (insertRows.length>0) {\x0d\x0a for (var i=0;i0) {\x0d\x0a for (var k=0;k0) {\x0d\x0a for (var j=0;j<deleteRows.length;j++) {\x0d\x0a changesRows.deleted.push(deleteRows[j]);\x0d\x0a }\x0d\x0a } \x0d\x0a\x0d\x0a$.ajax({\x0d\x0a type: "post", \x0d\x0a url: "../stock/stock_modify.asp", \x0d\x0a\x0d\x0a data: "inserted="+JSON.stringify(changesRows.inserted)+"&updated="+JSON.stringify(changesRows.updated)+"&deleted="+JSON.stringify(changesRows.deleted), \x0d\x0a datatype: "json",\x0d\x0a success:function(data){\x0d\x0a\x0d\x0a} \x0d\x0a\x0d\x0a})\x0d\x0a\x0d\x0a以上是针对插入删除更新 操作

返回的是rows数组项是json对象,不是数组,无法通过下标获取,你需要通过dom关系找到第一列的列名称,然后通过rows[i][名称]来获取
  var colName=$('#tt').parent().find('table.datagrid-htable td:eq(0)').attr('field');//得到第一列的名称
var ids = [];
var rows = $('#tt').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
ids.push(rows[i][colName]);/////
}
alert(ids.join('\n'));本回答被提问者和网友采纳

一周热门 更多>