据我所知我没有做错任何事,但它就是行不通。 我只是想将一个字符串插入 $scope.Array。
这是我的代码:
var _length = currentNieuws.textImages.length;
for (var i = 0; i < _length; i++) {
var _str = currentNieuws.textImages[i];
$scope.textImages.push(_str);
}
你看到我做错了什么了吗?
最佳答案
发生这种情况是因为您从 currentNieuws.textImages
获取并添加到 $scope.textImages
。
我确定你没有在 $scope 中初始化这个数组。
在上面的某个地方你应该做 $scope.textImages = []
或者另一种变体:避免循环并执行
$scope.textImages = currentNieuws.textImages;
关于javascript - $scope.name.push() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084595/