我必须为 ng-repeat 和我正在使用的 $index
按顺序生成数字(连续数字),但这再次为我提供了从 1 到第二个 ng- 的序列重复
。
我尝试在范围内获取一个变量,然后在 View 中递增,但这也没有奏效。
代码:
<body ng-controller="MainCtrl">
<ul ng-repeat="detail in details">
<li><span>{{$index + 1}}</span><span> {{detail.name}}</span>
</li>
</ul>
<ul ng-repeat="detailed in details.name">
<li><span>{{$index + 1}}</span><span>{{detailed.prof}}</span></li>
</ul>
</body>
Controller :
app.controller('MainCtrl', function($scope) {
$scope.details = [
{ "name": "Employees" },
{ "name": "Support" }
];
$scope.details.name = [
{ "prof": "enginerr" },
{ "prof": "doctor" }
];
});
在此 plunker 工程师编号应为 3,医生编号应为 4。
如有任何帮助,我们将不胜感激。
最佳答案
将details.length
添加到第二个ng-repeat
<body ng-controller="MainCtrl">
<ul ng-repeat="detail in details">
<li><span>{{$index + 1}}</span><span> {{detail.name}}</span>
</li>
</ul>
<ul ng-repeat="detailed in details.name">
<li><span>{{details.length + $index + 1}}</span><span>{{detailed.prof}}</span></li>
</ul>
关于javascript - 在 ng-repeat 中按顺序生成数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41023347/