我有一个angularjs页面,它有一个ng-repeat <ul>数据点列表。每个<li>都有一个删除链接(称为删除1),点击时需要隐藏该删除1链接并在其位置显示另外2个链接:取消和删除(称为删除2)。点击取消链接后,需要显示原始删除1链接,并且需要隐藏取消和删除2链接。目前所有这些都有效,但现在有一个新的要求。angularjs ngrepeat设置数组值不工作
当单击删除1链接时,其他列表项上的所有“取消和删除2”链接对都需要隐藏。由于AngularJS是基于单一操作的,我为deleteLinkClick和cancelLinkClick创建了一个函数来完成所需的复杂操作。
当您查看下面提供的控制器代码时,您会看到show标志被设置为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...
这是我(的CoffeeScript)控制器代码:
@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