新建列表A和表格B,三个按钮1,2,3
添加如下事件,点击按钮1,列表A设置为[1,1,1,1,1],将列表A加入表格B
点击按钮2,列表A设置为[2,2,2,2,2],将列表A加入表格B
点击按钮3,列表A设置为[3,3,3,3,3],将列表A加入表格B
调试场景,点击按钮1,预计结果是A为[“1”,“1”,"1","1","1"],B为[[“1”,“1”,"1","1","1"]],实际结果A为[“1”,“1”,"1","1","1"],B为[[“1”,“1”,"1","1","1"]],A、B都正确
再点击按钮2,预计结果是A为[“2”,“2”,"2","2","2"],B为[[“1”,“1”,"1","1","1"],[“2”,“2”,"2","2","2"]],实际结果A为[“2”,“2”,"2","2","2"],B为[[“2”,“2”,"2","2","2"],[“2”,“2”,"2","2","2"]],A正确B错误
再点击按钮3,预计结果是A为[“3”,“3”,"3","3","3"],B为[[“1”,“1”,"1","1","1"],[“2”,“2”,"2","2","2"],[“3”,“3”,"3","3","3"]],实际结果A为[“3”,“3”,"3","3","3"],B为[[“3”,“3”,"3","3","3"],[“3”,“3”,"3","3","3"],[“3”,“3”,"3","3","3"]],A正确B错误
为什么每次给B加列表A,B原来的列都变成最新的列表A了?
“将列表A加入表格B”这个操作,你是用了哪个积木,貌似没有加入表格的积木,只有加入列表的积木。
出现这个结果,按我的理解是,将列表A加入表格B,表格B里面记录的实际上不是列表A里实际的数值,而是表格B记录了列表A的引用地址,所以当点击按钮2和点击按钮3之后,表格B上记录的实际上是3个列表A的地址,并且列表A已经变成最新的[“3”,“3”,"3","3","3"],所以表格B显示为[[“3”,“3”,"3","3","3"],[“3”,“3”,"3","3","3"],[“3”,“3”,"3","3","3"]]
想将列表里的值记录到表格,建议还是用遍历的方式一个一个填进去吧。