dwr增加行DWRUtil.addRows

我现在用dwr做增加行的例子。现在得到一个list然后遍历根据list的length来添加。现在的问题是当list.length的值是1的时候是增加了一行。当值是2的时候问题就出现了。是加了4行同样的加了2行。3的时候是6行了同样的加了3行。不知道是不是DWRUtil.addRows的问题啊。 :cry:
[b]问题补充:[/b]
代码
[code="java"]
<br> function addrow(sysid)<br> {<br><br> DWRUtil.removeAllRows(&quot;imgtable&quot;);<br> DwrUtils.queryFileName(sysid,backFunction);<br> }</p> <pre><code> function backFunction(data) { for(var i=0;i&lt;data.length;i++) { var name=data[i].fileName; DWRUtil.addRows(&quot;imgtable&quot;,data,[function(data){return name}]); } } &lt;/script&gt; </code></pre> <p>[/code]</p>

官方不是有遍历的例子吗?为什么不参考呢?我看你的写法和官方的差别很大

问题出在你代码,你那个var只赋值了一次.

/**

  • Create rows inside a the table, tbody, thead or tfoot element (given by id).
  • @see http://getahead.org/dwr/browser/tables
    */
    dwr.util.addRows = function(ele, data, cellFuncs, options) {
    ele = dwr.util._getElementById(ele, "addRows()");
    if (ele == null) return;
    if (!dwr.util._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) {
    dwr.util._debug("addRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + dwr.util._detailedTypeOf(ele));
    return;
    }
    if (!options) options = {};
    if (!options.rowCreator) options.rowCreator = dwr.util._defaultRowCreator;
    if (!options.cellCreator) options.cellCreator = dwr.util._defaultCellCreator;
    var tr, rowNum;
    if (dwr.util._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 = dwr.util._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 = dwr.util._addRowInner(cellFuncs, options);
    if (tr != null) ele.appendChild(tr);
    rowNum++;
    }
    }

    dwr.util.highlight(ele, options);
    };