gpt4 book ai didi

javascript - AngularJS:使用列表项作为单独列表的变量

转载 作者:行者123 更新时间:2023-12-02 17:22:14 25 4
gpt4 key购买 nike

因此,在我的 Controller 中,我有这些数组,其中包含对象项:

$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,它就会返回未定义。有任何想法吗?谢谢

最佳答案

$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);
}
}

关于javascript - AngularJS:使用列表项作为单独列表的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23834830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com