Angular - 如何在 angular 中动态创建二维数组?
Angular - How to create 2d array in angular dynamically?
我一直在想办法动态地创建这个数组并将其发送到我的 api
。数组结构如下。
Photos[image][0] = "a.png"
Photos[image][1] = "b.png"
Photos[image][2] = "c.png"
我如何在控制器中执行此操作我每次应用某些解决方案时都会卡住,我会收到此错误 Cannot set property '0' of undefined angular array
。我想我还是不知道这是什么数组。到目前为止,我已经实施了这个解决方案,但天知道为什么会让人头疼。
我在这个对象中有三个文件
$scope.files = [file,file,file].
并且我需要将它们以我上面提到的所需格式放入数组中。这是我的代码。
for (var i = 0; i < $scope.file.length; i++) {
Photos[image] = {};
Photos[image][i]= $scope.file[i];
}
console.log(Photos);
请详细说明我的错误。
我会查看 angular foreach 的文档。
这将允许您遍历 $scope.files 中的每个文件。然后可以将每个文件添加到您认为合适的照片数组中。
我一直在想办法动态地创建这个数组并将其发送到我的 api
。数组结构如下。
Photos[image][0] = "a.png"
Photos[image][1] = "b.png"
Photos[image][2] = "c.png"
我如何在控制器中执行此操作我每次应用某些解决方案时都会卡住,我会收到此错误 Cannot set property '0' of undefined angular array
。我想我还是不知道这是什么数组。到目前为止,我已经实施了这个解决方案,但天知道为什么会让人头疼。
我在这个对象中有三个文件
$scope.files = [file,file,file].
并且我需要将它们以我上面提到的所需格式放入数组中。这是我的代码。
for (var i = 0; i < $scope.file.length; i++) {
Photos[image] = {};
Photos[image][i]= $scope.file[i];
}
console.log(Photos);
请详细说明我的错误。
我会查看 angular foreach 的文档。
这将允许您遍历 $scope.files 中的每个文件。然后可以将每个文件添加到您认为合适的照片数组中。