我有一个 angularjs 页面,其中有一个 ng-repeat <ul> 数据点列表。每个 <li> 都有一个删除链接(称为删除 1),单击该链接时需要隐藏删除 1 链接并在其位置显示另外 2 个链接:取消和删除(称为删除 2)。当点击取消链接时,原来的删除1链接需要显示,取消和删除2链接需要隐藏。所有这些目前都有效,但现在有一个新的要求。
单击删除 1 链接时,其他列表项上的所有“取消和删除 2”链接对都需要隐藏。由于 AngularJS 是基于单一动作的,我为 deleteLinkClick 和 cancelLinkClick 创建了一个函数来执行所需的复杂动作。
当您查看下面提供的控制器代码时,您会看到显示标志设置为 false,但它不起作用。建议?
这是我的(苗条)html页面:
... OTHER STUFF...
ul
li.address ng-repeat="data in request.theData" ng-init="showWarning=[]"
.address-li
.address-details
p
|Field 1: {{data.field1}}
span ng-if="data.field2!=''"
br
|Field 2: {{data.field2}}
span
span.button-small.button-cancel ng-show="!showWarning[$index]" ng-click="deleteLinkClick(showWarning,$index)" Delete
span.button-small.button-cancel ng-show="showWarning[$index]" ng-click="cancelLinkClick(showWarning,$index)" Cancel
span.button-small.button-delete.button-warn ng-show="showWarning[$index]" ng-click="deleteAddress($index)" Delete
... OTHER STUFF...
这是我的(咖啡脚本)控制器代码:
@MyPage.controller('MyController',
['$scope', '$rootScope', '$location', 'NtdRequest', 'Form', '$anchorScroll'
($scope, $rootScope, $location, ntd_request, form, $anchorScroll) ->
$scope.currentIndex = -1
$scope.cancelLinkClick = (array,index) ->
array[index] = false
$scope.currentIndex = -1
$scope.deleteLinkClick = (array,index) ->
if ($scope.currentIndex != -1)
array[$scope.currentIndex] = false
array[index] = true
$scope.currentIndex = index
]
)
先感谢您
-wh