Ионный трек по ошибке с трутовыми картами

Я начал изучать Ionic 2 недели назад, и сейчас я создаю небольшой проект для практики. Вы можете скачать мой проект с моего Github: https://github.com/KaanYildirim/ionicTest

Я пытаюсь использовать карты типа Tinder, созданные самой ионной командой. (https://github.com/driftyco/ionic-ion-tinder-cards)

Я пробовал все возможные решения с выражением "track by", но все равно получаю эту ошибку:

Ошибка: [ngRepeat: dupes] Дубликаты в репитере не допускаются. Используйте выражение «отслеживать по», чтобы указать уникальные ключи. Повторитель: карта в карточках отслеживается по card.id, Повторяющийся ключ: undefined, Повторяющееся значение: undefined

Я пытался исправить эту ошибку с помощью «отслеживать по индексу» и «отслеживать по card.id» (каждая карта имеет атрибут «id» в файле .Json), но это не сработало. Думаю, я сделал небольшую ошибку и не могу ее найти.

Кто-нибудь может мне помочь? Спасибо

index.html:

 	  <td-cards>
      <td-card ng-repeat="card in cards track by card.id" on-destroy="cardDestroyed($index)" on-swipe="cardSwiped($index)">
        <div class="list card myCard">

          <!-- Card Header-->
          <div class="item topicDescription cardHeader">
             <p>{{card.topicDescription}}</p>
          </div>

          <!-- Card Body-->
          <div class="item item-body noBorder">
            <img class="full-image" src="{{card.image}}">
            <h3 class="cardTitle">{{card.title}}</h3>
            <p>{{card.summary}}</p>  
          </div>

          <!-- Card Footer-->
          <div class="item tabs tabs-secondary tabs-icon-left cardFooter">
             <a class="tab-item" ng-click="readMore($index)" href="#">
                 <i class="{{card.actionButtonIcon}}"></i>
                 {{card.actionButtonText}} {{card.type}} ( {{card.additionalInfo}} )
             </a>

             <a class="tab-item" ng-click="share($index)" href="#">
                <i class="icon ion-share"></i>
                Share
              </a>
          </div>
        </div>
      </td-card>
    </td-cards>

Файл Json:

{
  "articles": [
    {
      "id":1,
      "topicDescription": "Find a Idea",
      "image": "img/uber.jpg",
      "title": "Uber Lowers Fares In Over 100 Cities",
      "summary": "Uber is lowering prices in over 100 U.S. and Canadian cities, effective tomorrow. January is a slower month for the car service and the company says it is reducing fares in order to increase demand.",
      "link": "http://techcrunch.com/2016/01/08/uber-lowers-fares-in-over-100-cities/",
      "actionButtonIcon": "icon ion-ios-glasses-outline",
      "actionButtonText": "Read",
      "type":"Article",
      "additionalInfo": "3 min"
    },
    {
      "id":2,
      "topicDescription": "Test a Idea",
      "image": "img/lean.jpg",
      "title": "The Lean Startup",
      "summary": "Great book about startups and how to validate your idea without spending to much money and time.",
      "link": "http://www.amazon.de/Lean-Startup-Innovation-Successful-Businesses/dp/0670921602/ref=sr_1_2?ie=UTF8&qid=1452779528&sr=8-2&keywords=the+lean+startup",
      "actionButtonIcon": "icon ion-ios-bookmarks-outline",
      "actionButtonText": "Buy",
      "type":"Book",
      "additionalInfo": "Amazon"
    },
    {
      "id":3,
      "topicDescription": "Build",
      "image": "img/evernote.jpg",
      "title": "Note Taking App",
      "summary": "From short lists to lengthy research, no matter what form your writing takes, Evernote keeps you focused on moving those ideas from inspiration to completion.",
      "link": "https://evernote.com/?var=3",
      "actionButtonIcon": "icon ion-hammer",
      "actionButtonText": "Download",
      "type":"App",
      "additionalInfo": "App Store"
    },
    {
      "id":4,
      "topicDescription": "Measure",
      "image": "img/steve.jpg",
      "title": "Steve Blank: How to Build a Great Company",
      "summary": "Join Silicon Valley serial entrepreneur-turned-educator Blank in a lively discussion with Dan'l Lewin of Microsoft. This program will introduce best practices, lessons and tips that have swept the startup world, offering a wealth of proven advice and information for entrepreneurs of all stripes.",
      "link": "https://www.youtube.com/watch?v=1RTcXwJuCaU",
      "actionButtonIcon": "icon ion-ios-videocam-outline",
      "actionButtonText": "Watch",
      "type":"Video",
      "additionalInfo": "Youtube"
    },
    {
      "id":5,
      "topicDescription": "Find a Idea",
      "image": "img/uber.jpg",
      "title": "Uber Lowers Fares In Over 100 Cities",
      "summary": "Uber is lowering prices in over 100 U.S. and Canadian cities, effective tomorrow. January is a slower month for the car service and the company says it is reducing fares in order to increase demand.",
      "link": "http://techcrunch.com/2016/01/08/uber-lowers-fares-in-over-100-cities/",
      "actionButtonIcon": "icon ion-ios-glasses-outline",
      "actionButtonText": "Read",
      "type":"Article",
      "additionalInfo": "3 min"
    },
    {
      "id":6,
      "topicDescription": "Test a Idea",
      "image": "img/lean.jpg",
      "title": "The Lean Startup",
      "summary": "Great book about startups and how to validate your idea without spending to much money and time.",
      "link": "http://www.amazon.de/Lean-Startup-Innovation-Successful-Businesses/dp/0670921602/ref=sr_1_2?ie=UTF8&qid=1452779528&sr=8-2&keywords=the+lean+startup",
      "actionButtonIcon": "icon ion-ios-bookmarks-outline",
      "actionButtonText": "Buy",
      "type":"Book",
      "additionalInfo": "Amazon"
    },
    {
      "id":7,
      "topicDescription": "Build",
      "image": "img/evernote.jpg",
      "title": "Note Taking App",
      "summary": "From short lists to lengthy research, no matter what form your writing takes, Evernote keeps you focused on moving those ideas from inspiration to completion.",
      "link": "https://evernote.com/?var=3",
      "actionButtonIcon": "icon ion-hammer",
      "actionButtonText": "Download",
      "type":"App",
      "additionalInfo": "App Store"
    },
    {
      "id":8,
      "topicDescription": "Measure",
      "image": "img/steve.jpg",
      "title": "Steve Blank: How to Build a Great Company",
      "summary": "Join Silicon Valley serial entrepreneur-turned-educator Blank in a lively discussion with Dan'l Lewin of Microsoft. This program will introduce best practices, lessons and tips that have swept the startup world, offering a wealth of proven advice and information for entrepreneurs of all stripes.",
      "link": "https://www.youtube.com/watch?v=1RTcXwJuCaU",
      "actionButtonIcon": "icon ion-ios-videocam-outline",
      "actionButtonText": "Watch",
      "type":"Video",
      "additionalInfo": "Youtube"
    }
  ]
}


person Kaan Yıldırım    schedule 16.01.2016    source источник
comment
Включите в вопрос соответствующие части вашего кода, это поможет людям определить проблему и дать конкретные ответы. И добро пожаловать в StackOverflow!   -  person plamut    schedule 16.01.2016
comment
Спасибо за ответ. Я не знал, в чем проблема, поэтому загрузил весь проект.   -  person Kaan Yıldırım    schedule 16.01.2016


Ответы (1)


Я изучил ваш код. В файле controllers.js вы обрабатываете событие cardSwiped, вручную добавляя неопределенную карту в свой список.

$scope.cardSwiped = function(index) {
        var newCard = // new card data
         $scope.cards.push(newCard);
    };

Это приводит к тому, что ваши карты содержат несколько неопределенных элементов, которые ng-repeat будет вынужден обрабатывать как дубликаты. Удалите / исправьте этот обработчик, и все должно работать.

Кстати, этот код будет работать нормально, потому что javascript будет обрабатывать их как одну строку var newCard = $scope.cards.push(newCard); Это означает, что в конце функции ваша переменная newCard будет иметь новую длину массива карт.

person Hisham    schedule 16.01.2016
comment
Я получаю это сейчас. Еще раз спасибо !! - person Kaan Yıldırım; 16.01.2016