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)
...
{
varorig=ele;
ele=$(ele);

if(ele==null)...{
DWRUtil.debug("addRows()can'tfindanelementwithid:"+orig+".");
return;
}

if(!DWRUtil._isHTMLElement(ele,["table","tbody","thead","tfoot"]))...{
DWRUtil.debug("addRows()canonlybeusedwithtable,tbody,theadandtfootelements.Attempttouse:"+DWRUtil._detailedTypeOf(ele));
return;
}

//假如传进来的是tableid,则找到table的tbody

if(DWRUtil._isHTMLElement(ele,["table"]))...{
varchildren=ele.children

for(varh=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;
vartr,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);
}
}
}

elseif(typeofdata=="object")...{
rowNum=0;

for(varrowIndexindata)...{
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
++
)
...
{
varmyTD=myTR.insertCell();
myTD.innerText=rowno+","+i;
}
//2007-813
在上面的代码是在dwr1.1.3版本上测试通过
在目前的dwr2.0.1上依然存在这个bug,把红色的代码copy进去就可以了,把DWRUtil改为dwr.util