Reactjs 如何为react创建二维阵列
这是我迄今为止为生成网格中坐标列表的Reactjs 如何为react创建二维阵列,reactjs,Reactjs,这是我迄今为止为生成网格中坐标列表的getCoordinates函数编写的代码 getCoordinates = () => { let result = [] for (int i = 1; i <= this.state.gridSize; i++){ for (int j = 1; j <= this.state.gridSize; j++){ result.push([i*100,
getCoordinates
函数编写的代码
getCoordinates = () => {
let result = []
for (int i = 1; i <= this.state.gridSize; i++){
for (int j = 1; j <= this.state.gridSize; j++){
result.push([i*100, j*100])
}
}
return result;
};
有人能帮我找到正确的语法吗?这里的问题是变量
i
和j
的声明。目前,它们是用Java(或类似)语法声明的。相反,那些int
关键字应替换为let
像这样:
getCoordinates=()=>{
让结果=[]
for(让i=1;i?注意,将实际输出作为您的一部分(甚至在发布之前,搜索您的错误消息)是有帮助的。
[[100, 100], [100, 200], [100, 300], [100, 400],
[200, 100], [200, 200], [200, 300], [200, 400],
[300, 100], [300, 200], [300, 300], [300, 400],
[400, 100], [400, 200], [400, 300], [400, 400]]