当我发出警报时,我只得到 i 的最后一个值。找不到我哪里出错了
$scope.addToList = function (products,qty) {
if ($scope.order.length > 0) {
for (var i = 0; i < $scope.order.length; i++) {
$scope.Thx=$scope.order[i].id;
}}};
alert($scope.Thx);
最佳答案
首先将 $scope.Thx
声明为数组。
$scope.Thx = [];
$scope.addToList = function (products, qty) {
if ($scope.order.length > 0) {
for (var i = 0; i < $scope.order.length; i++) {
$scope.Thx.push($scope.order[i].id);
}
}
};
关于javascript - 如何获取for循环 Angular js中的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50467086/