AngularJs ng-repeat with index [英] AngularJs ng-repeat with index
问题描述
我想仅在单击显示按钮时在此部分中显示名称.我正在尝试使用索引进行检测,但没有成功.
代码
:
<a ng-click="display(c.id[$index])" ng-hide="点击后需要隐藏">{{vm.updateText}}</a><div ng-show="c.id[$index]" class="updateSection"><input type="text" name="id" data-ng-model="id"/><input type="button" ng-click="vm.veryId(id)" value="{{vm.verifyButtonText}}"><input type="button" ng-click="vm.Cancel()" value="{{vm.cancelButtonText}}">
//将显示 ng-click="vm.veryId(id)"<rpe-progress data-ng-show="vm.showProgress" block="true"></rpe-progress>//如果 id 正在工作,将显示以下错误消息:<rpe-alert show="vm.mpnIdAlert">{{vm.errormessage}}</rpe-alert><脚本>vm.display= 函数(索引){vm.id[index] = true;//我想要显示更新部分 &隐藏更新文本}vm.cancel=函数(){//我想隐藏 updatesection &显示更新文本}vm.veryId= 函数 (id) {//如果 id 错误,则显示错误消息.}
@Pevara 发布的逻辑绝对没问题.我建议你采用这种逻辑.
我不明白您的问题的实际用例.所以,如果你真的想用 $index
值来完成这个逻辑,你可以使用下面的代码片段来完成你的任务.
var app = angular.module('app', []);app.controller('indexCtrl', function ($scope) {$scope.customers = [{名称:'ABC',年龄:26},{名称:'DEF',年龄:32},{名称:'GHI',年龄:21}];$scope.toggleDisplay = 函数(索引){$scope.customers[index].show = !$scope.customers[index].show;};});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="样式表"/><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><body ng-app="app"><div ng-controller="indexCtrl"><table class="table"><tr><td>姓名</td><td>年龄</td></tr><tr ng-repeat="c 在客户中"><td>{{c.name}}</td><td><button ng-click="toggleDisplay($index)">Display</button><span ng-show="c.show">{{c.Age}}</span></td></tr>