我对 AngularJS 很陌生,所以我确定我只是犯了一个简单的错误。
我想var newCard = cardTypes.shift();
在线上拼接 cardTypes 数组而不是使用.shift()
,这样我就可以考虑我的 ng-repeat 索引。
它可以正常工作,.shift()
但如果我尝试,则根本没有数据通过.splice(index, 1)
。
任何帮助将不胜感激。
.controller('CardsCtrl', function($scope, $ionicSwipeCardDelegate) {
var cardTypes = [
{ title: 'Swipe down to clear the card', image: 'img/pic.png' },
{ title: 'Where is this?', image: 'img/pic.png' },
{ title: 'What kind of grass is this?', image: 'img/pic2.png' },
{ title: 'What beach is this?', image: 'img/pic3.png' },
{ title: 'What kind of clouds are these?', image: 'img/pic4.png' }
];
$scope.cards = Array.prototype.slice.call(cardTypes, 0, 0);
$scope.cardSwiped = function(index) {
$scope.addCard();
};
$scope.cardDestroyed = function(index) {
$scope.cards.splice(index, 1);
$scope.addCard();
};
$scope.addCard = function() {
var newCard = cardTypes.shift();
newCard.id = Math.random();
$scope.cards.push(angular.extend({}, newCard));
}
})
.controller('CardCtrl', function($scope, $ionicSwipeCardDelegate) {
$scope.goAway = function() {
var card = $ionicSwipeCardDelegate.getSwipebleCard($scope);
card.swipe();
};
});