0

私はAngularJSにかなり慣れていないので、単純な間違いを犯していると確信しています。

ng-repeat インデックスを考慮できるようにvar newCard = cardTypes.shift();、使用するのではなく、行に cardTypes 配列をスプライスしたいと考えています。.shift()

で問題なく動作し.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();
  };
});
4

1 に答える 1

1

addCard機能の話ですか?

indexその関数には変数がないので.splice(0, 1);、最初の変数を削除するつもりだったのでしょうか?

'use strict';すべての JavaScript ファイルの先頭に追加することで、そのような問題を見つけることができました。

于 2014-04-11T16:38:58.057 に答える