Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the new list as an array? #100

Open
idesignzone opened this issue Dec 4, 2023 · 1 comment
Open

How to get the new list as an array? #100

idesignzone opened this issue Dec 4, 2023 · 1 comment

Comments

@idesignzone
Copy link

I have trouble getting the new array list.
here is my code

<template>
  <div>
    <Sortable :list="elements" item-key="id" tag="div" :options="options" @change="DragableData($event)">
      <template #item="{ element, index }">
        <div :key="element.id">
          {{ index }} - {{ element.name }}
        </div>
      </template>
    </Sortable>
  </div>
</template>

<script setup>
const elements = [
  { id: "1", name: "one" },
  { id: "2", name: "two" },
  { id: "3", name: "three" },
  { id: "4", name: "four" },
];
const options = {sort: true};

function DragableData(data) {
  console.log(data)
}
</script>

data here does not have any array in it. is it possible to get new array?

@eazyurk
Copy link

eazyurk commented Dec 11, 2023

I did the following on the Sortable element I added:
@end="(event) => onEnd(event)"

Then the onEnd function:

function onEnd(event) {
    array.splice(event.newIndex, 0, array.splice(event.oldIndex, 1)[0]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants