dwr中addRows方法存在bug 方法原型:DWRUtil.addRows(id, array, cellfuncs, [options]);
dwr文档说明addRows的id可以是table、tbody,theader、tfoot等任何一个标签的id, 但是,若传递table的id,则增加的行不会显示,这就涉及到dom在add row的行为,这里就不多说了,简单一点就是若想通过dom增加行的话,就一定要通过tbody来执行,关于这些资料,可以在网上找到的,这里我们是要解决dwr的问题
下面是修改后的addRows源代码,增加了检测传进来的id是否是table id,这样就可以解决问题了
DWRUtil.addRows
=
function
(ele, data, cellFuncs, options)
...
{ var orig = ele; ele = $(ele); if (ele == null ) ... { DWRUtil.debug( " addRows() can't find an element with id: " + orig + " . " ); return ; } if ( ! DWRUtil._isHTMLElement(ele, [ " table " , " tbody " , " thead " , " tfoot " ])) ... { DWRUtil.debug( " addRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele)); return ; } // 假如传进来的是table id,则找到table的tbody if (DWRUtil._isHTMLElement(ele, [ " table " ])) ... { var children = ele.children for ( var h = 0 ; h < children.length; h ++ ) ... { if (children[h].nodeName.toLowerCase() == " tbody " ) ... { ele = children[h]; break ; } } } if ( ! options) options = ... {} ; if ( ! options.rowCreator) options.rowCreator = DWRUtil._defaultRowCreator; if ( ! options.cellCreator) options.cellCreator = DWRUtil._defaultCellCreator; var tr, rowNum; if (DWRUtil._isArray(data)) ... { for (rowNum = 0 ; rowNum < data.length; rowNum ++ ) ... { options.rowData = data[rowNum]; options.rowIndex = rowNum; options.rowNum = rowNum; options.data = null ; options.cellNum = - 1 ; tr = DWRUtil._addRowInner(cellFuncs, options); if (tr != null ) ... { ele.appendChild(tr); } } } else if ( typeof data == " object " ) ... { rowNum = 0 ; for ( var rowIndex in data) ... { options.rowData = data[rowIndex]; options.rowIndex = rowIndex; options.rowNum = rowNum; options.data = null ; options.cellNum = - 1 ; tr = DWRUtil._addRowInner(cellFuncs, options); if (tr != null ) ele.appendChild(tr); rowNum ++ ; } } }
;
增加行的方法还可以使用insertRow()方法,table,tbody,thead,tfoot都有这个方法,下面是关于这个方法的使用:
var
mytable
=
document.getElementById(
"
myTable
"
);
var
myTR
=
mytable.insertRow();
var
rowno
=
mytable.rows.length;
for
(
var
i
=
0
; i
<
3
; i
++
)
...
{ var myTD = myTR.insertCell(); myTD.innerText = rowno + " , " + i; }