我使用ionic和angularjs創建應用程序。在應用程序開發過程中,我使用離子的swipe選項從主列表中刪除特定的優惠券。我在這裏面臨的問題是,Im只能刪除所選優惠券的說明,但無法從主列表中刪除/刪除優惠券。我還用$rootScope
在那裏宣佈我的json array
。我已經申報了一個$scope.item
,其中所選優惠券及其詳細信息將被推入,以便顯示每個選定優惠券的說明。我在代碼的某個地方出錯了,請幫助我解決問題。謝謝。如何從列表中刪除項目
HTML:
<ion-list>
<ion-item ng-click="select_item(coupons)" ng-repeat="coupons in couponList" ng-model="coupons.selected">
{{coupons.CouponTitle}} <br>
<ion-option-button ng-click="editCoupons(coupons)">Edit</ion-option-button>
<ion-option-button class="button-assertive" ng-click="deleteSelected(coupons)">Delete</ion-option-button>
</ion-item>
</ion-list>
<hr>
<div style="text-align:center">
<div ng-repeat="item in items">
Coupon offer: {{item.data.description}}<br> Valid From: {{item.data.Fromldate}}
<br> Valid Till: {{item.data.Todate}} </div>
控制器:
$scope.items = [];
$rootScope.couponList = [{ CouponTitle: "Purchase worth $100", data: {description: "$50 off", Fromldate: "2016-09-09", Todate: "2016-09-18"}},
{CouponTitle: "Purchase worth $300", data:{description: "$75 off", Fromldate: "2016-11-09", Todate: "2016-10-19"}},
{ CouponTitle: "Purchase worth $500",data:{description: "$95 off", Fromldate: "2016-09-10", Todate: "2016-09-30"}}];
$scope.select_item = function (key) {
$scope.items.push(key);
}
$scope.deleteSelected = function() {
$scope.items.splice($scope.items.indexOf());
}
@jazzoria,請檢查我的答案。 – Sravan
你能解釋一下如何使用'ng-repeat'來解決這個問題。請 – jazzoria
這是一樣的,你檢查,檢查小提琴鏈接, 'ng-model =「coupons.selected」>「ng-model =」coupons.selected「>」
Sravan