gpt4 book ai didi

javascript - 嵌套的 ng-repeat 显示错误的 $index

转载 作者:行者123 更新时间:2023-11-29 21:31:57 25 4
gpt4 key购买 nike

我尝试使用 ng-repeat 但是当 $index 一直显示错误的东西时卡住了这是我的代码 http://codepen.io/netwrkx/pen/VamRjo

<div ng-controller="ctrl">
<div class="row responsive-sm " ng-repeat="items in DataAPI">
<div class="card1" ng-repeat="item in items">
<div class="row">
<div class="">
<input type="submit" ng-click="showFullPost($index)"></input>
<h4 class="post-title">{{item}} {{$index}}</h4>
</div>
</div>
</div>
</div>
</div>

function ctrl($scope){
$scope.items = ["orange", "mango", "grape", "apple", "pineapple", "lemon"];

$scope.DataAPI = [["orange", "mango"],["grape", "apple"], [ "pineapple", "lemon"]];

$scope.showFullPost = function(index){
console.log($scope.items[index] );
//$state.go('post');
}

}

尝试循环

child $scope.items = ["橙子", "芒果", "葡萄", "苹果", "菠萝", "柠檬"];

parent $scope.DataAPI = [["orange", "mango"],["grape", "apple"], [ "pineapple", "lemon"]];

$index 一直只显示橙色和芒果。我错过了什么??

任何想法...

最佳答案

这将标记项目 0、1、2、3、4、5。

<div ng-repeat="items in DataAPI track by $index">
<div ng-repeat="item in items" ng-init="idx = $parent.$index * items.length + $index">
<button ng-click="showFullPost(idx)">View Full</button>
<h4 class="post-title">{{item}} {{idx}}</h4>
</div>
</div>

关于javascript - 嵌套的 ng-repeat 显示错误的 $index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36025852/

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