0

我的页面上有一个可选 div 网格,其中包含定义行和列的属性。当我选择其中一些时,将创建三维表 - 让我们将其命名为表副本。

当我再次选择其他一些元素时,会创建其他三维表 - 表粘贴

第一次选择两列两行后

   x,y - positions
   at1,at2,at2 - attributes for later copy

                             Table Copy
                          1                2
                0:[x,y,at1,at2,at3],[x,y,at1,at2,at3]
                1:[x,y,at1,at2,at3],[x,y,at1,at2,at3]

在选择三列三行后,它看起来像这样

                             Table Copy
                          1                2
                0:[x,y,at1,at2,at3],[x,y,at1,at2,at3]
                1:[x,y,at1,at2,at3],[x,y,at1,at2,at3]

                             Table Paste
                  1                2                 3               
       0:[x,y,at1,at2,at3],[x,y,at1,at2,at3],[x,y,at1,at2,at3]
       1:[x,y,at1,at2,at3],[x,y,at1,at2,at3],[x,y,at1,at2,at3]
       2:[x,y,at1,at2,at3],[x,y,at1,at2,at3],[x,y,at1,at2,at3]

现在我需要一个函数,它只需用表格副本中的内容填充表格粘贴

                             Table Paste
                  1                2                 3               
            0:[tabCopy[0][1]],[tabCopy[0][2]],[tabCopy[0][1]]
            1:[tabCopy[1][1]],[tabCopy[1][1]],[tabCopy[1][1]]
            2:[tabCopy[0][1]],[tabCopy[0][2]],[tabCopy[0][1]]

当然,两个数组的大小都有很多可能性。

表格复制可以有 4 行,表格粘贴只能有 3 行。那么表格复制的第四行应该被“忽略”。

如果表复制仅在 1 行 1 列中,则表粘贴中的所有记录应该看起来相同

如果表粘贴只有 1 行 1 列,它应该只取表复制中的第一条记录。

我希望我清楚地描述了一切:)

感谢帮助

4

1 回答 1

0

好吧,让我们看看我是否理解你...

function copyArrays(from, to) {
    for (var i = 0, j = 0; i < to.length;
         i++, j = (j + 1) % from.length) {
        if ((from[j] instanceof Array) &&
            (to[i] instanceof Array)) {
            copyArrays(from[j], to[i]);
        } else {
            to[i] = from[j];
        }
    }
}

var from = [["x", "y", "at1", "at2", "at3"],
            ["x", "y", "at1", "at2", "at3"],
            ["x", "y", "at1", "at2", "at3"],
            ["x", "y", "at1", "at2", "at3"]];

var to = [["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"],
          ["+", "-", "123", "456", "789"]];

然后:

copyArrays(from, to);

会给你:

[["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"], 
 ["x", "y", "at1", "at2", "at3"]]
于 2013-07-30T14:55:29.013 回答