Skip to content

Commit 950f7d4

Browse files
author
pc-david\david.desmaisons
committed
Improve update on two lists
1 parent 8b5361b commit 950f7d4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

examples/src/vuedragablefor.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@
2020
var options = this.params.options;
2121
if (typeof options === "string")
2222
options = JSON.parse(options);
23-
console.log(options);
2423
options = _.merge(options,{
2524
onUpdate: function (evt) {
26-
console.log(evt.oldIndex, evt.newIndex);
2725
var collection = ctx.collection;
2826
if (!!collection)
2927
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
3028
},
3129
onAdd: function (evt) {
3230
var itemEl = evt.item; // dragged HTMLElement
33-
evt.from; // previous list
31+
var directive = evt.from.__directive; // previous list
32+
if (!directive)
33+
return;
34+
ctx.collection.splice(evt.newIndex, 0, directive.collection[evt.oldIndex]);
3435
},
3536
onRemove: function (evt) {
3637
}
3738
});
39+
var parent = this.el.parentElement;
40+
parent.__directive = this;
3841
console.log(options);
3942
//var option =
40-
this.sortable = new Sortable(this.el.parentElement, options);
43+
this.sortable = new Sortable(parent, options);
4144
},
4245
update : function (value){
4346

src/vuedragablefor.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@
2020
var options = this.params.options;
2121
if (typeof options === "string")
2222
options = JSON.parse(options);
23-
console.log(options);
2423
options = _.merge(options,{
2524
onUpdate: function (evt) {
26-
console.log(evt.oldIndex, evt.newIndex);
2725
var collection = ctx.collection;
2826
if (!!collection)
2927
collection.splice(evt.newIndex, 0, collection.splice(evt.oldIndex, 1)[0] );
3028
},
3129
onAdd: function (evt) {
3230
var itemEl = evt.item; // dragged HTMLElement
33-
evt.from; // previous list
31+
var directive = evt.from.__directive; // previous list
32+
if (!directive)
33+
return;
34+
ctx.collection.splice(evt.newIndex, 0, directive.collection[evt.oldIndex]);
3435
},
3536
onRemove: function (evt) {
3637
}
3738
});
39+
var parent = this.el.parentElement;
40+
parent.__directive = this;
3841
console.log(options);
3942
//var option =
40-
this.sortable = new Sortable(this.el.parentElement, options);
43+
this.sortable = new Sortable(parent, options);
4144
},
4245
update : function (value){
4346

0 commit comments

Comments
 (0)