sagalbot / vue-sortable

A lightweight directive for reorderable drag-and-drop lists using RubaXa/Sortable
http://sagalbot.github.io/vue-sortable/
MIT License
721 stars 104 forks source link

How to get object with sorted items? #6

Closed 6pm closed 8 years ago

6pm commented 8 years ago

I add object with options in list then init plugin. After sorting items source object remained unchanged. Нow to get sorted object? Whether this plugin can't this?

nblackburn commented 8 years ago

@6pm The model doesn't appear to be synced in this plugin (looking at the code)

LostKobrakai commented 8 years ago

Using this in the options for sortable does work for me.

onUpdate: function (evt) {
  var old = evt.oldIndex,
      now = evt.newIndex,
      data = this.data; // Replace with your own array to sort

    data.splice(now, 0, data.splice(old, 1)[0]);
}.bind(this)
sagalbot commented 8 years ago

Sorry for the slow response, but @LostKobrakai has the right approach. @nblackburn is correct, the plugin does not make any assumptions about your data. This is the same approach that you'd have to take if you were using sortable outside of Vue.

I will add this approach to the docs.

ypresto commented 8 years ago

This should be in official docs..!

ypresto commented 8 years ago

It'd be very useful if there is option to specify data array. E.g. v-sortable="{model: data}"

ypresto commented 8 years ago

Or sotable-array="data", which can be implemented by params: ['sotable-array'] in directive.