所以在我的控制器中,我有这些数组,其中包含对象项:
$scope.johnny = [
{quote: "Anything for My Princess", path: 'sounds/AnythingForMyPrincess.mp3'},
{quote: "Don't Even Ask", path: 'sounds/DontEventAsk.mp3'},
{quote: "Don't Plan Too Much", path: 'sounds/DontPlanTooMuch.mp3'}
] //there are many more lists like this one
我想通过使用另一个数组(数组的名称)和一个for循环来遍历这些列表:
$scope.totalNames = [$scope.johnny, $scope.lisa, $scope.mark, $scope.denny, $scope.lisasmom,
$scope.chicken, $scope.chris, $scope.flower, $scope.mike, $scope.steven]
for (var i = 0; i < $scope.totalNames.length; i++) {
var list = $scope.totalNames[i];
alert(list.quote);
}
$ scope.totalNames [i]返回正确的数组;但是,一旦我将.quote添加到它,它就会返回undefined。有任何想法吗?谢谢
最佳答案
$scope.totalNames
是列表的列表。您应该这样:
for (var i = 0; i < $scope.totalNames.length; i++) {
var list = $scope.totalNames[i];
for (var j = 0; j < list.length; j++) {
alert(list[j].quote);
}
}