使用javascript用另一个表的内容填充该表
我的页面上有一个可选div的网格,属性定义行和列。当我选择其中一些时,将创建三维表格-让我们将其命名为table Copy 当我再次选择一些其他元素时,将创建另一个三维表格-表格粘贴 第一次选择两列两行后,它将使用javascript用另一个表的内容填充该表,javascript,arrays,copy,Javascript,Arrays,Copy,我的页面上有一个可选div的网格,属性定义行和列。当我选择其中一些时,将创建三维表格-让我们将其命名为table Copy 当我再次选择一些其他元素时,将创建另一个三维表格-表格粘贴 第一次选择两列两行后,它将 x,y - positions at1,at2,at2 - attributes for later copy Table Copy 1
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]
现在我需要一个函数,它可以用tablecopy中的内容填充表粘贴
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列,则应仅获取表副本中的第一条记录
我希望我把一切都描述清楚:)
谢谢你的帮助好吧,让我看看我是否理解你的意思
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"]];
将为您提供:
[["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"]]
[["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"]]