List move item duplicating / overwriting


#1

I have a really random issue with an ion-list When moving an item it replaces the item in the indexTo position.

This video demonstrates best.

My code is:

$scope.moveItem = function(exercise, fromIndex, toIndex) {

      console.log(exercise);

      $scope.exercises.splice(fromIndex, 1);
      $scope.exercises.splice(toIndex, 0, exercise);

      console.log($scope.exercises);
};

The object structure of exercise is:

 {
        "exerciseDescription": "Stand on one leg and straighten",
        "exerciseName": "Pistol Squats",
        "images": [
            248,
            250
        ]
    }

Anyone seen this before?


#2

Any ideas @mhartington? I believe this was ok before upgrading to Angular 1.3?


#3

Hmm, do you have a codepen example of this?


#4

Yep:

See the Pen PqZybN by Simon Taylor (@Taylorsuk) on CodePen.

Data structure issue?


#5

Adding some logging

$scope.moveItem = function(exercise, fromIndex, toIndex) {
  console.log('moving from ' + angular.toJson(fromIndex) + ' to ' + toIndex);

shows that fromIndex is actually an exercise object. That’s because you’re passing an extra exercises argument:

moveItem(exercises,exercise, $fromIndex, $toIndex)

#6

Sorry thats my bad… I have corrected this and it works in the pen - i still get exactly the same as in the video at the top of this post.


#7

Odd, works fine for me in both Chrome and Firefox.


#8

Yeah the codepen is working fine - I am unable to recreate my issue in codpen… :frowning: