angular-ui / ui-sortable

jQuery UI Sortable for AngularJS
http://angular-ui.github.io/ui-sortable/
MIT License
1.26k stars 444 forks source link

sorted array is not retained #560

Open jyoti-openair opened 5 years ago

jyoti-openair commented 5 years ago

So, I have an array as

var groups = [{
  name: 'Applicants',
  place: 'NY'
},{
  name: 'Volunteer',
  place: 'CA'
},{
  name: 'Others',
  place: 'LA'
}];

so when I drag and sort it. I'm saving it to cookies. as follows:

var groupsObj = {
     groups: ui.item.sortable.droptargetModel
 }
 $cookies.putObject('groups', groupsObj);

when I console.log ui.item.sortable.droptargetModel it gives me correct sorted array. ex:

[{
  name: 'Applicants',
  place: 'NY'
},{
  name: 'Others',
  place: 'LA'
},{
  name: 'Volunteer',
  place: 'CA'
}];

But when I get the cookies as follows:

$cookies.getObject('groups'); it's giving me initial array instead of sorted array.

[{ name: 'Applicants',
  place: 'NY'
},{
  name: 'Volunteer',
  place: 'CA'
},{
  name: 'Others',
  place: 'LA'
}];

I'm not sure what the problem is, is it reference problem ?

thgreasi commented 5 years ago

It could be. Can you try doing droptargetModel.slice() ? Also in which option are you setting b the cookie?