删除数据的时候,如果表格中只有一条数据(如果有多条数据,没有问题),那么删除时就会弹出窗体,说: 指定行号为:null。但是数据能够删除成功(刷新后,就会发现,数据已经删除了),控制台也不报错。我查了代码,发现是JSP页面的一行代码这出的问题。
如下:
financeTable().deleteRow(rowIndex)
financeTable()是我得到表格对象的用一个js方法,
deleteRow()是公司框架封装的一个由于在页面上删除数据的js方法(只是在页面上删除,数据库里的数据还需要自己去删除一下):function  TableRowSet_deleteRow(rowIndex){
   if(rowIndex == null)
     rowIndex = this.CurRow;   if ((rowIndex >=0) && (rowIndex < this.count())){
      var sts = this.getRowSts(rowIndex);
      if((sts!='NN')&& (sts!='N')){
        var tmpRow = new Array();
        tmpRow.I = this.getRowId(rowIndex);
        var tmpCell;
        for(var i=0;i<this.getColCount();i++){
           tmpCell = new TableRowSet_VCell();
           this.copyCell(this.getCell(rowIndex,i)[/color],tmpCell);
           tmpRow[tmpRow.length] = (tmpCell);
        }
        this.deleteRows[this.deleteRows.length] = (tmpRow);
      }
      for(var i = rowIndex ;i < this.count() - 1; i++){
           this.rowHideCols[i] = this.rowHideCols[i + 1]
      }
      this.rowHideCols[this.count() - 1] = null;      //如果是删除第一行,需求将后续的一行的单元格的属性进行设置 qianghui 20060428
      var dataTable = this.getTableObject();
      if(rowIndex ==0 &&  dataTable.rows.length >1){
           for(var i = 0;i <  this.HeadTable.rows(0).cells.length ;i++){
               dataTable.rows(1).cells(i).width = this.HeadTable.rows(0).cells(i).width;
           }
      }      //如果有儿子节点,将儿子节点的父亲设置为自己的父亲
      //同时将后面的节点索引减1
      var tmpChildList = this.getChildList(rowIndex);
      var tmpParentRowIndex = this.getParentOfRow(rowIndex);
      for(var i= tmpChildList.length-1 ;i>=0;i--){
          this.setParent(tmpChildList[i],tmpParentRowIndex);
      }
      if(this.DBTreeColName){
         //没有指定DBTree的列
         this.setParent(rowIndex,-1);
      }
      this.recomputerChildRowIndex(this.getTableObject().rows.length - 1,rowIndex,this.getTableObject().rows.length - 1,-1);      this.getTableObject().deleteRow(rowIndex);      if ( this.CurRow > rowIndex)
           this.CurRow  = this.CurRow - 1;
      else if( this.CurRow == rowIndex){
          if(this.CurRow == this.count())
              this.setRow(this.CurRow - 1);
      }
   }   this.currentRowChange(this.CurRow,-1);
   this.recomputerTotalAll();   this.modifyTotalRowCount(this.totalRowCount - 1);
   this.modifyRowSequence(rowIndex);   //hexg ,20060903,更新headdiv的长度
   TableRowSet_setHeadDivWidth(this.HeadDiv,this.TableDiv);}function TableRowSet_getCell(rowIndex,colIndex){   var tmpRow = this.getRowObj(rowIndex);
   if (tmpRow == null)
     return null;
   if((colIndex == null)||(colIndex<0)||(colIndex >= this.getColCount()))
      return null;
   if (this.colIsHide[colIndex] ==false ){
        return tmpRow.cells(colIndex +   this.getRowHeadColCount());
   }
   else  {//获取隐藏的虚拟单元
     if(this.rowHideCols[rowIndex] ==  null){   //从数据Row的属性中提取隐藏列数据
        this.rowHideCols[rowIndex] =  new Array();
        for(var i= this.visioColCount;i< this.getColCount();i++){
          this.rowHideCols[rowIndex][i - this.visioColCount]  = new  TableRowSet_VCell();          var tmpID = "";
          eval(" tmpID = tmpRow." + this.colNames[i]);          //如果是属性中包含&nbsp;的话,则IE会将其转换成字节码为160的字符,16进制为A0
          var str_160 = String.fromCharCode(160);
          if(tmpID!=null && tmpID.indexOf(str_160)>-1){
           tmpID = tmpID.replace(/\xA0/g,' ');
           eval("tmpRow." + this.colNames[i] + " = tmpID");
          }          var tmpText = "";
          eval(" tmpText = tmpRow." + this.colNames[i] +"_DISPLAY");
          if(!tmpText){
             this.rowHideCols[rowIndex][i - this.visioColCount ].innerText = tmpID;
          }else{
             this.rowHideCols[rowIndex][i - this.visioColCount ].innerText = tmpText;
             this.rowHideCols[rowIndex][i - this.visioColCount ].I = tmpID;
          }
       }
     }     return this.rowHideCols[rowIndex][ colIndex - this.visioColCount];
   }  }
function TableRowSet_getRowObj(rowIndex){
  if([color=#FF0000]rowIndex == null
){
    alert(g_I18NMessage("appframe_core","table_row_null"));    return null;
  }
  rowIndex = parseInt(rowIndex);
  if ((rowIndex >=0)&&(rowIndex < this.realcount()))
     return this.getTableObject().rows(rowIndex);
  else
     return null;
}
图中标红的代码,就是报错的代码。如果table中只用1行数据,我删除时,公司封装的js方法,回去遍历每隔单元格cell。当循环到这行数据最后一个单元格时,行号就变成了空我真是郁闷了。别的table删除也是用这个js,没有问题

解决方案 »

  1.   


    删除数据的时候,如果表格中只有一条数据(如果有多条数据,没有问题),那么删除时就会弹出窗体,说: 指定行号为:null。但是数据能够删除成功(刷新后,就会发现,数据已经删除了),控制台也不报错。我查了代码,发现是JSP页面的一行代码这出的问题。
    如下:
    financeTable().deleteRow(rowIndex)
    financeTable()是我得到表格对象的用一个js方法,
    deleteRow()是公司框架封装的一个由于在页面上删除数据的js方法(只是在页面上删除,数据库里的数据还需要自己去删除一下):function TableRowSet_deleteRow(rowIndex){
      if(rowIndex == null)
      rowIndex = this.CurRow;  if ((rowIndex >=0) && (rowIndex < this.count())){
      var sts = this.getRowSts(rowIndex);
      if((sts!='NN')&& (sts!='N')){
      var tmpRow = new Array();
      tmpRow.I = this.getRowId(rowIndex);
      var tmpCell;
      for(var i=0;i<this.getColCount();i++){
      tmpCell = new TableRowSet_VCell();
      this.copyCell(this.getCell(rowIndex,i),tmpCell);
      tmpRow[tmpRow.length] = (tmpCell);
      }
      this.deleteRows[this.deleteRows.length] = (tmpRow);
      }
      for(var i = rowIndex ;i < this.count() - 1; i++){
      this.rowHideCols[i] = this.rowHideCols[i + 1]
      }
      this.rowHideCols[this.count() - 1] = null;  //如果是删除第一行,需求将后续的一行的单元格的属性进行设置 qianghui 20060428
      var dataTable = this.getTableObject();
      if(rowIndex ==0 && dataTable.rows.length >1){
      for(var i = 0;i < this.HeadTable.rows(0).cells.length ;i++){
      dataTable.rows(1).cells(i).width = this.HeadTable.rows(0).cells(i).width;
      }
      }  //如果有儿子节点,将儿子节点的父亲设置为自己的父亲
      //同时将后面的节点索引减1
      var tmpChildList = this.getChildList(rowIndex);
      var tmpParentRowIndex = this.getParentOfRow(rowIndex);
      for(var i= tmpChildList.length-1 ;i>=0;i--){
      this.setParent(tmpChildList[i],tmpParentRowIndex);
      }
      if(this.DBTreeColName){
      //没有指定DBTree的列
      this.setParent(rowIndex,-1);
      }
      this.recomputerChildRowIndex(this.getTableObject().rows.length - 1,rowIndex,this.getTableObject().rows.length - 1,-1);  this.getTableObject().deleteRow(rowIndex);  if ( this.CurRow > rowIndex)
      this.CurRow = this.CurRow - 1;
      else if( this.CurRow == rowIndex){
      if(this.CurRow == this.count())
      this.setRow(this.CurRow - 1);
      }
      }  this.currentRowChange(this.CurRow,-1);
      this.recomputerTotalAll();  this.modifyTotalRowCount(this.totalRowCount - 1);
      this.modifyRowSequence(rowIndex);  //hexg ,20060903,更新headdiv的长度
      TableRowSet_setHeadDivWidth(this.HeadDiv,this.TableDiv);}function TableRowSet_getCell(rowIndex,colIndex){  var tmpRow = this.getRowObj(rowIndex);
      if (tmpRow == null)
      return null;
      if((colIndex == null)||(colIndex<0)||(colIndex >= this.getColCount()))
      return null;
      if (this.colIsHide[colIndex] ==false ){
      return tmpRow.cells(colIndex + this.getRowHeadColCount());
      }
      else {//获取隐藏的虚拟单元
      if(this.rowHideCols[rowIndex] == null){ //从数据Row的属性中提取隐藏列数据
      this.rowHideCols[rowIndex] = new Array();
      for(var i= this.visioColCount;i< this.getColCount();i++){
      this.rowHideCols[rowIndex][i - this.visioColCount] = new TableRowSet_VCell();  var tmpID = "";
      eval(" tmpID = tmpRow." + this.colNames[i]);  //如果是属性中包含&nbsp;的话,则IE会将其转换成字节码为160的字符,16进制为A0
      var str_160 = String.fromCharCode(160);
      if(tmpID!=null && tmpID.indexOf(str_160)>-1){
      tmpID = tmpID.replace(/\xA0/g,' ');
      eval("tmpRow." + this.colNames[i] + " = tmpID");
      }  var tmpText = "";
      eval(" tmpText = tmpRow." + this.colNames[i] +"_DISPLAY");
      if(!tmpText){
      this.rowHideCols[rowIndex][i - this.visioColCount ].innerText = tmpID;
      }else{
      this.rowHideCols[rowIndex][i - this.visioColCount ].innerText = tmpText;
      this.rowHideCols[rowIndex][i - this.visioColCount ].I = tmpID;
      }
      }
      }  return this.rowHideCols[rowIndex][ colIndex - this.visioColCount];
      }  }
    function TableRowSet_getRowObj(rowIndex){
      if(rowIndex == null){
      alert(g_I18NMessage("appframe_core","table_row_null")); return null;
      }
      rowIndex = parseInt(rowIndex);
      if ((rowIndex >=0)&&(rowIndex < this.realcount()))
      return this.getTableObject().rows(rowIndex);
      else
      return null;
    }
    图中标红的代码,就是报错的代码。如果table中只用1行数据,我删除时,公司封装的js方法,回去遍历每隔单元格cell。当循环到这行数据最后一个单元格时,行号就变成了空我真是郁闷了。别的table删除也是用这个js,没有问题
      

  2.   

    解决了我吐血,虽然最终解决了,但是现在我还糊里糊涂的,自己当初怎么想到去那里找原因我周四改了几个bug判断当前行的某个单元格的可编辑状态的
    删除和判断状态是在2个function里,应该不影响啊,但可能是我的那个判断可编辑状态的function是在某个单元格的焦点离开事件触发,所以出现了这个问题我看了下,主要是我获取当前行的一个方法那的问题那个也是公司封装的一个js方法,得到当前选择的行,返回的是一个行号的数组这个方法在别的之前在别的地方使用时没有问题虽然解决了,但我也知道底层是怎么回事。下周把那个方法贴上来,大家给给指点一下