javascript - 隐藏除单击行之外的所有表格行 AngularJS

标签 javascript html angularjs

我有一个用 ng-repeat 填充的表。单击该行时,我将使用 ng-click 检索与该对象相关的数据。该表由 json 文件填充。单击所选行时如何隐藏表格的所有其他行?

<table class="table table-bordered table-striped">
    <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Age</th>
        </tr> 
    </thead>
    <tbody style="cursor: pointer" ng-cloak> <!--When the row is clicked, I want to hide all other rows except the clicked one.-->
        <tr ng-repeat="person in people" ng-click="getSelected(person);">
            <td>{{ person.firstName }}</td>
            <td>{{ person.lastName }}</td>
            <td>{{ person.age }}</td>
        </tr>
    </tbody>
</table>

<script>
    angular.module("App", []).controller("MainController", function ($scope) {
        $scope.people = peopleData;
        $scope.getSelected = function (person) {
            $scope.selected = person;
        };
    });
</script>

最佳答案

尝试将以下内容添加到您的 <tr> 中。它基本上是说,如果有一个选择并且该选择不是当前正在迭代的人,则隐藏此行。

ng-hide="selected && selected !== person"

关于javascript - 隐藏除单击行之外的所有表格行 AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41641831/

相关文章:

html - Bootstrap 3 : Thumbnail caption text wrapping to second line makes container height stretch

php - 在 jQuery 选项卡脚本中默认加载选项卡

javascript - 将 EXT JS 按钮的样式用于基本 HTML 按钮

javascript - Angular UI 路由器 : Cannot log inside of . 配置

javascript - 二进制搜索以查找最接近目标的数字。未定义为返回值

javascript - 如何为图像制作响应式自动幻灯片?

javascript - 为什么 `toString` 不等于 `window.toString` ?

javascript - 将方法传递给函数

javascript - Controller 没有在angularjs中被调用

javascript - 如何使用 AngularJs 将数组插入对象数组