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都有这个方法,下面是关于这个方法的使用:
varmytable=document.getElementById("myTable");
varmyTR=mytable.insertRow();
varrowno=mytable.rows.length;
for(vari=0;i<3;i++)...{
varmyTD=myTR.insertCell();
myTD.innerText=rowno+","+i;
}
//2007-813
在上面的代码是在dwr1.1.3版本上测试通过
在目前的dwr2.0.1上依然存在这个bug,把红色的代码copy进去就可以了,把DWRUtil改为dwr.util
本文介绍DWR中addRows方法的一个bug,并提供了解决方案。该bug导致当使用table ID时,新增行无法正常显示。通过修改源代码检查ID类型并确保使用tbody进行操作,解决了这一问题。
608

被折叠的 条评论
为什么被折叠?



