如果选择了另一行,Angularjs会隐藏行

时间:2018-04-27 09:34:30

标签: angularjs hide show

我有一个html / angularjs表,其中包含ff:

 <tbody ng-repeat="x in Persons">
                    <tr>
                        <td>{{x.FirstName}}</td>
                        <td>{{x.LastName}}</td>
                        <td>{{x.Department}}</td>                           
                        <td>
                            <a href"#" data-ng-click="x.show = !x.show">
                             Sales Details
                            </a>

                        </td>
                    </tr>
                    <tr>
                     <td ng-show="x.show">
                        <!--user sales details here-->
                     </td>
                    </tr>
    </tbody>

目前,如果我点击第一行显示详细信息,但我需要再次单击它以隐藏它。如果单击第二行,我想隐藏第一行详细信息。我该怎么做?

2 个答案:

答案 0 :(得分:1)

你需要一个方法来实现这个

看一看 https://stackblitz.com/edit/js-tv6dog?file=index.js

JS:

<td>
  <a href"#" data-ng-click="clicked($index)">
  Sales Details
 </a>
</td>

HTML

<tbody ng-repeat="x in Persons track by $index">

当然要添加跟踪到ng-repeat

topicName

答案 1 :(得分:1)

试试这个。我希望这正是你想要的。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="name">
<table>
<tbody ng-repeat="x in Persons">
                    <tr>
                        <td>First Name</td>                   
                        <td>
                            <a href"#/" style="color:red" ng-click="showorhide($index)">
                           open/close
                            </a>

                        </td>
                    </tr>
                    <tr ng-show="x.show">
                     <td >
                        {{x.FirstName}}
                     </td>
                    </tr>
    </tbody>
    </table>
</div>
&#13;
int[] f = {17,17,22,19};
int[] m = {21,19,24,22,20,23,18};
for(int i = 0; i < m.length; i++)
    {
         for(int j = 0; j < f.length; j++)
        {
             if(m[i] == f[j])
            {
                System.out.printf(m[i] + " ");//showing common 
            }
        }
    }
&#13;
&#13;
&#13;