Javascript 在数组中的数组上使用ng repeat
我试图使用ng repeat遍历JSON数组和成分/方向数组。我的东西坏了。有什么建议吗?谢谢 控制器:Javascript 在数组中的数组上使用ng repeat,javascript,arrays,json,angularjs,ng-repeat,Javascript,Arrays,Json,Angularjs,Ng Repeat,我试图使用ng repeat遍历JSON数组和成分/方向数组。我的东西坏了。有什么建议吗?谢谢 控制器: recipeControllers.controller('DetailsController', ['$scope', '$http','$routeParams', function($scope, $http, $routeParams) { $http.get('app/data.json').success(function(data) { $scope.recipe =
recipeControllers.controller('DetailsController', ['$scope', '$http','$routeParams',
function($scope, $http, $routeParams) {
$http.get('app/data.json').success(function(data) {
$scope.recipe = data;
$scope.whichItem = $routeParams.itemId;
$scope.recipeIngredients = recipe[whichItem].ingredients;
}]);
HTML:
<div class="recipe">
<div class="ingredients">
<ul>
<li ng-repeat="item in recipeIngredients">{{recipeIngredients[whichItem].ingredients}}</li>
</ul>
</div>
</div>
如果您正确地分配
$scope.recipeingElements
(即元素已正确设置并映射到JSON数据中的实际对象),则$scope.recipeingElements
已指向一系列成分(例如[“duck”、“confit”、“otherstuff”]
),因此要进行迭代,您只需执行以下操作:
<li ng-repeat="item in recipeIngredients">{{item}}</li>
如果您正确地分配$scope.recipeingElements
(即元素已正确设置并映射到JSON数据中的实际对象),则$scope.recipeingElements
已指向一系列成分(例如[“duck”、“confit”、“otherstuff”]
),因此要进行迭代,您只需执行以下操作:
<li ng-repeat="item in recipeIngredients">{{item}}</li>
如果您正确地分配$scope.recipeingElements
(即元素已正确设置并映射到JSON数据中的实际对象),则$scope.recipeingElements
已指向一系列成分(例如[“duck”、“confit”、“otherstuff”]
),因此要进行迭代,您只需执行以下操作:
<li ng-repeat="item in recipeIngredients">{{item}}</li>
如果您正确地分配$scope.recipeingElements
(即元素已正确设置并映射到JSON数据中的实际对象),则$scope.recipeingElements
已指向一系列成分(例如[“duck”、“confit”、“otherstuff”]
),因此要进行迭代,您只需执行以下操作:
<li ng-repeat="item in recipeIngredients">{{item}}</li>
itemId
是要显示的项的0索引索引吗?或者是其他原因。实际的ng repeat
在哪里?我是一个新手程序员,所以请原谅任何明显的错误。不一定需要ng repeat,尽管问题提到尝试使用它但没有显示出来很奇怪。@KevinB,问题是关于“尝试迭代…使用ng repeat”itemId
是要显示的项的0索引索引吗?或者是其他原因。实际的ng repeat
在哪里?我是一个新手程序员,所以请原谅任何明显的错误。不一定需要ng repeat,尽管问题提到尝试使用它但没有显示出来很奇怪。@KevinB,问题是关于“尝试迭代…使用ng repeat”itemId
是要显示的项的0索引索引吗?或者是其他原因。实际的ng repeat
在哪里?我是一个新手程序员,所以请原谅任何明显的错误。不一定需要ng repeat,尽管问题提到尝试使用它但没有显示出来很奇怪。@KevinB,问题是关于“尝试迭代…使用ng repeat”itemId
是要显示的项的0索引索引吗?或者是其他原因。实际的ng repeat
在哪里?我是一个新手程序员,所以请原谅任何明显的错误。不一定需要ng repeat,尽管问题提到尝试使用它但没有显示出来很奇怪。@KevinB,问题是关于“尝试迭代…使用ng repeat”whichItem映射到我从上一页选择的任何配方(JSON对象),因此我不确定如何正确分配$scope.RecipeIngCredits您已经可以使用$scope.RecipeIngCredits=recipe[whichItem].Components代码>(实际上,它应该是$scope.recipe[whichItem].ingre…
或数据[whichRecipe].ingre…
)例如,如果我只使用{{recipe[whichItem].components} ,那么我将在一行中返回整个字符串。我希望每种配料都有自己的配方。非常感谢您迄今为止的帮助。@breken,我给了您答案。。。您的$scope.recipeIndents
已经指向配料数组(如果您修复了我提到的输入错误/错误)-因此,ng重复
,我非常感谢您的帮助,但它似乎仍然不起作用。然而,我可能误解了你的指示。控制器:$scope.recipe=数据$scope.whichItem=$routeParams.itemId$scope.data[whichItem]。成分=接受成分;在我的HTML中:{{recipe.dish}- {{item}}
它映射到我从上一页选择的任何配方(JSON对象),因此,我不确定如何正确分配$scope.recipeIngredients您已经可以使用
$scope.recipeIngredients=recipe[whichItem].components代码>(实际上,它应该是$scope.recipe[whichItem].ingre…
或数据[whichRecipe].ingre…
)例如,如果我只使用{{recipe[whichItem].components} ,那么我将在一行中返回整个字符串。我希望每种配料都有自己的配方。非常感谢您迄今为止的帮助。@breken,我给了您答案。。。您的$scope.recipeIndents
已经指向配料数组(如果您修复了我提到的输入错误/错误)-因此,ng重复
,我非常感谢您的帮助,但它似乎仍然不起作用。然而,我可能误解了你的指示。控制器:$scope.recipe=数据$scope.whichItem=$routeParams.itemId$scope.data[whichItem]。成分=接受成分;在我的HTML中:{{recipe.dish}- {{item}}
它映射到我从上一页选择的任何配方(JSON对象),因此,我不确定如何正确分配$scope.recipeIngredients您已经可以使用
$scope.recipeIngredients=recipe[whichItem].components代码>(实际上,它应该是$scope.recipe[whichItem].ingre…
或数据[whichRecipe].ingre…
)例如,如果我只使用{{recipe[whichItem].components} ,那么我将在一次查询中返回整个字符串