【发布时间】:2014-05-25 21:59:48
【问题描述】:
我对 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();
};
});
【问题讨论】:
-
我看不出这与 Angular 有什么关系。
标签: javascript arrays angularjs ionic-framework