修正dwr中addRows方法的bug
来源:互联网 发布:儿童日本js蓝光眼镜 编辑:程序博客网 时间:2024/05/01 23:46
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++;
}
}
};
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;
}
var myTR = mytable.insertRow();
var rowno = mytable.rows.length;
for (var i=0; i<3; i++){
var myTD=myTR.insertCell();
myTD.innerText=rowno+", "+i;
}
//2007-813
在上面的代码是在dwr1.1.3版本上测试通过
在目前的dwr2.0.1上依然存在这个bug,把红色的代码copy进去就可以了,把DWRUtil改为dwr.util
- 修正dwr中addRows方法的bug
- 修正dwr中addRows方法的bug
- DWR中 DWRUtil.addRows() 方法详解
- DWR的DWRUtil.addRows方法的使用
- DWR的DWRUtil.addRows()函数
- 修正bug的方法
- DWR 的 DWRUtil.addRows() 函数的使用
- DWR 的 DWRUtil.addRows() 函数的使用
- DWR 的 DWRUtil.addRows() 函数的使用
- DWR 的 DWRUtil.addRows() 函数的使用
- DWR 的 DWRUtil.addRows() 函数的使用
- XUBUNTU-8.04-a6版本中安装BCM43XX无线网卡的BUG修正方法
- CCEditBox的bug修正
- dwr convertXml的bug
- 关于cocos2dx播放音效的bug以及修正方法
- ReportBuilder 中ppMemo不支持中文换行的Bug 的修正
- 修正IEWebControls中TreeView的一处bug
- 修正TEmbeddedWEB不能使用中键滚动的bug
- 前微软中国总监 到尼泊尔盖学校
- Oracle知识点总结二
- Oracle基本知识点总结三
- 比较orale的tnsping与TCP/IP的ping命令
- 时评:大学徒见“大门”不见“大师”
- 修正dwr中addRows方法的bug
- 国际COM域名安全问题受到质疑
- JS对象和数组大全
- 研究僧生涯开始了
- 分页
- 如何配置才能使客户端连到数据库(oracle)
- orcale10g客户端信息
- J2ME小特效之闪电中的城市
- IT行业趋势前沿:SOA和开源