|
69 | 69 | options = _.merge(options,{
|
70 | 70 | onStart: function (evt) {
|
71 | 71 | indexes = computeIndexes(_.chain(evt.from.children));
|
| 72 | + console.log(indexes); |
72 | 73 | },
|
73 | 74 | onUpdate: function (evt) {
|
| 75 | + if (ctx.params.trackBy==="$index"){ |
| 76 | + removeNode(evt.item); |
| 77 | + insertNodeAt(evt.from, evt.item, evt.oldIndex); |
| 78 | + } |
74 | 79 | updatePosition(ctx.collection, evt.newIndex, evt.oldIndex);
|
75 | 80 | },
|
76 |
| - onAdd: function (evt) { |
77 |
| - indexes = computeIndexes(_.chain(evt.to.children).filter(function(elt){return elt!==evt.item;})); |
78 |
| - console.log(indexes); |
79 |
| - if (!!ctx.collection){ |
| 81 | + onAdd: function (evt) { |
| 82 | + if (!!ctx.collection){ |
80 | 83 | var addElement= getVmObject(evt.item);
|
81 |
| - var length = indexes.length; |
| 84 | + var localIndexes = computeIndexes(_.chain(evt.to.children).filter(function(elt){return elt!==evt.item;})); |
| 85 | + var length = localIndexes.length; |
82 | 86 | if (evt.newIndex>= length){
|
83 | 87 | ctx.collection.push(addElement);
|
84 | 88 | }
|
85 | 89 | else{
|
86 |
| - var newIndex = indexes[evt.newIndex]; |
| 90 | + var newIndex = localIndexes[evt.newIndex]; |
87 | 91 | ctx.collection.splice(newIndex, 0, addElement);
|
88 | 92 | }
|
89 | 93 | }
|
90 | 94 | },
|
91 | 95 | onRemove: function (evt) {
|
92 | 96 | var collection = ctx.collection;
|
93 |
| - if (!!collection && !evt.clone){ |
| 97 | + var isCloning = !!evt.clone; |
| 98 | + if (!!collection && !isCloning){ |
| 99 | + //If is cloning is set no need to remove element from collection |
94 | 100 | var realOld = indexes[evt.oldIndex];
|
95 | 101 | collection.splice(realOld, 1);
|
96 | 102 | }
|
97 |
| - if (!!evt.clone){ |
| 103 | + if (isCloning){ |
98 | 104 | removeNode(evt.clone);
|
99 |
| - insertNodeAt(evt.from, evt.item, evt.oldIndex) |
| 105 | + insertNodeAt(evt.from, evt.item, evt.oldIndex); |
100 | 106 | }
|
101 | 107 | else{
|
102 |
| - //remove added node: Vue will add it for us |
| 108 | + //Need to remove added node if Vue is not tracking it: Vue will add it for us |
103 | 109 | var elt = evt.item
|
104 | 110 | if (!!getFragment(elt).parentFrag){
|
105 | 111 | removeNode(elt);
|
|
0 commit comments