编程语言
首页 > 编程语言> > javascript-如何仅针对单击angularJS ng-show和ng-hide的表行定位

javascript-如何仅针对单击angularJS ng-show和ng-hide的表行定位

作者:互联网

我在angularJS应用中有一张桌子.我想做的是添加一个切换功能来显示/隐藏表数据部分.该函数有效,但是会切换表中的每一行.我只需要切换单击的行即可:这是一个示例截屏视频:http://screencast.com/t/U5XXU7RN3gm

html

<tr data-toggle="modal" data-ng-repeat="program in listPrograms | orderBy:predicatemodal:reverse | filter: searchPrograms" isdisabled-program ng-click="setSelected(this)" ng-class="selected">
<td>
    <div popover-placement="right" popover-trigger="mouseenter" popover="{{program.programName}}">{{program.programName | characters:20}}</div>
</td>
<td>{{program.waDisplayName == null ? "N/A" :program.waDisplayName | characters:20}}</td>
<td>{{program.startDate}}</td>
<td>{{program.deadline}}</td>
<td >{{program.status}}</td>
<td>
    <div data-ng-hide="showButtons" class="showDate">{{program.updatedDate}}</div>
    <div data-ng-show="showButtons" class="showButtons">
        <a data-ng-click=""><i class="fa fa-pencil"></i>edit</a>
        <a data-ng-click=""><i class="fa fa-chevron-right"></i>details</a>
    </div>
</td>
<td class="program-arrows" data-ng-click="toggleArrows($index)">toggle arrows<span></span>
</td>
</tr>

javascript

$scope.toggleArrows = function (index) {
        $scope.showButtons = !$scope.showButtons;

    };

解决方法:

您正在修改“全局” showButtons属性.尝试为每个按钮提供一个属性:

<div data-ng-hide="program.showButtons" class="showDate">{{program.updatedDate}}</div>
<div data-ng-show="program.showButtons" class="showButtons">
    <!-- ... -->
</div>
$scope.toggleArrows = function (index) {
    var program = $scope.listPrograms[index];
    program.showButtons = !program.showButtons;
}

假设存在以下一种更好的解决方案:将该方法添加到程序的原型中:

Program.prototype.toggleArrows = function () {
    this.showButtons = !this.showButtons;
}
<td class="program-arrows" data-ng-click="program.toggleArrows()">toggle arrows<span></span>

标签:angularjs-ng-click,angularjs,javascript
来源: https://codeday.me/bug/20191121/2048879.html