我有一個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