简体   繁体   English

显示/隐藏按钮onclick在重复内的ng-repeat中

[英]Show/Hide button onclick in ng-repeat inside repeat

How can I access and show/hide the exact button in second repeat? 如何在第二次重复中访问和显示/隐藏确切的按钮?

<div class="row" ng-repeat="person in people">
  <div class="row" ng-repeat="ticket in tickets">
   <button type="button" ng-if="!ticket.added" ng-click="add(ticket)">+</button>
   <button type="button" ng-if="ticket.added" ng-click="remove(ticket)">-</button>
  </div>
</div>

For example I have 3 persons and 4 different tickets. 例如,我有3个人和4张不同的门票。 When someone click on button I want to add clicked ticket for that person. 当某人单击按钮时,我要添加该人的单击的票证。

Now when I click on add button, it's adding clicked ticket for all persons :( 现在,当我单击添加按钮时,它会添加所有人员的单击的票证:(

Thanks in advance! 提前致谢!

I'm not sure (your question is not too clear) but, maybe you can pass the person to your functions too? 我不确定(您的问题不太清楚),但是,也许您也可以将该传递给您的职能?

Example: 例:

$scope.people = [{
        name: 'Jhon Snow',
      tickets: [{
        name: 'ticket1',
        added: false
      }, {
        name: 'ticket2',
        added: false
      }]
    }, {
        name: 'Peter Parker',
      tickets: [{
        name: 'ticket3',
        added: false
      }, {
        name: 'ticket4',
        added: false
      }]
    }];    

    $scope.add = function (ticket) {
        ticket.added = true;      
    }

    $scope.remove = function (ticket) {
        ticket.added = false;
    }

And the html: 和html:

<div class="row" ng-repeat="person in people">
  {{ person.name}}
  <div class="row" ng-repeat="ticket in person.tickets">
    - {{ ticket.name }}
     <button type="button" ng-if="!ticket.added" ng-click="add(ticket)">+</button>
     <button type="button" ng-if="ticket.added" ng-click="remove(ticket)">-</button>
  </div>
</div>

You can check a working example here 您可以在此处查看一个有效的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM