所以在我的控制器中,我有这些带有对象项的数组:
$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。有任何想法吗?感谢
答案 0 :(得分:2)
$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);
}
}