EasyUi行编辑,新增行无法获取值? 5C

$("#tt").datagrid('getChanges', "inserted"); 获取得到的总是remark:'',得不到值,在线求解啊

    var editIndex = undefined;
        function endEditing(){
            if (editIndex == undefined){return true;}
            if ($('#tt').datagrid('validateRow', editIndex)){
                var ed = $('#tt').datagrid('getEditor', {index:editIndex,field:'packName'});
                var cn= $('#tt').datagrid('getEditor', {index:editIndex,field:'cateName'}); 

                var pn= $('#tt').datagrid('getEditor', {index:editIndex,field:'productName'}); 
                var sn=$('#tt').datagrid('getEditor',{index:editIndex,field:'sizeName' })
                if(ed!=null){
                    var packName = $(ed.target).combobox('getText');
                    $('#tt').datagrid('getRows')[editIndex]['packName'] = packName;
                }
                if(cn!=null){
                    var cateName = $(ed.target).combobox('getText');
                    $('#tt').datagrid('getRows')[editIndex]['packName'] = cateName;
                }
                if(pn!=null){
                    var productName = $(ed.target).combobox('getText');
                    $('#tt').datagrid('getRows')[editIndex]['productName'] = productName;
                }
                if(sn!=null){
                    var sizeName = $(ed.target).combobox('getText');
                    $('#tt').datagrid('getRows')[editIndex]['sizeName'] = sizeName;
                }
                //var cateName=$(cn.target).combobox('getText'); 

                //$('#tt').datagrid('getRows')[editIndex]['cateName'] = cateName; 
                $('#tt').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            } 
        }
        function onClickRow(index){
            if (editIndex != index){
                if (endEditing()){
                    $('#tt').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                } else {
                    $('#tt').datagrid('selectRow', editIndex);
                }
            }
        }
function append(){
            if (endEditing()){
                //1 先取消所有的选中状态
                $('#tt').datagrid('unselectAll');
                //2追加一行
                $('#tt').datagrid('appendRow',{
                    remark:''
                });
                //3获取当前页的行号
                editing = $('#tt').datagrid('getRows').length -1;
                //4选中并开启编辑状态
                $('#tt').datagrid('selectRow',editing);
                $('#tt').datagrid('beginEdit', editing);

                /* $('#tt').datagrid('appendRow',{status:'P'});
                editIndex = $('#tt').datagrid('getRows').length-1;
                $('#tt').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex); */
            }
        }
        function removeit(){
            if (editIndex == undefined){return}
            $('#tt').datagrid('cancelEdit', editIndex)
                    .datagrid('deleteRow', editIndex);
            editIndex = undefined;
        }
        function accept(){
            if (endEditing()){
                //$('#tt').datagrid('acceptChanges');
                //利用easyui控件本身的getChange获取新添加和修改的内容
                if($("#tt").datagrid('getChanges').length){
                    var inserted = $("#tt").datagrid('getChanges', "inserted");
                    var updated = $("#tt").datagrid('getChanges', "updated");   
                    var effectRow = new Object();
                    if (inserted.length) { 
                        effectRow["inserted"] = JSON.stringify(inserted);  
                    }
                    if(updated.length){
                        effectRow["updated"] = JSON.stringify(updated);
                    } 
                }


            }
        }

2个回答

你使用getChanges 意思为所有改变的行,可能获取不到新增行的数据,建议换成getRows 试一试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问