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 delete a node? #48

Closed
caiokawasaki opened this issue Dec 17, 2018 · 4 comments
Closed

How to delete a node? #48

caiokawasaki opened this issue Dec 17, 2018 · 4 comments

Comments

@caiokawasaki
Copy link

How to use the method deleteNode?

@alucidwolf
Copy link

@caiokawasaki did you figure this out?

@caiokawasaki
Copy link
Author

caiokawasaki commented May 9, 2019

@alucidwolf yes! Simple:

<draggable-tree :data="steps" draggable="draggable">
    <div class="step" slot-scope="{data, store}">
        <template>
            <a class="delete-trigger" href="#" @click.prevent="deleteStep(data)">Deletar</a>
        </template>
    </div>
</draggable-tree>

Inside methods:

deleteStep(step) {
    step._vm.store.deleteNode(step)
}

@alucidwolf
Copy link

@caiokawasaki Sweet! Thank you. I am using a Vuex store to render the data in a computed property, so once I remove the node, I call getPureData() and pass the new tree to a mutation to update the store.

<Tree :data="treeData" draggable="draggable">
  <div slot-scope="{data, store}">
    <div :class="data.children.length > 0 ? 'show-handle' : ''" v-if="!data.isDragPlaceHolder">
      <span @click="test(data, store)" class="icon-trash-alt"></span>
    </div>
  </div>
</Tree>

Method:

test(data, store) {
  store.deleteNode(data);

  let newData = store.getPureData();

  this.$store.commit("nestedDataTest/updateTree", [data]);
}

I am wondering if maybe I do not need to pass store down to the method just to access the getPureData() function on it. Will most likely move these into an action the delete and getPureData() then pass along the final object to a mutation.

Are you familiar with Vuex and have input on that? If not it's OK, you have helped me move forward already. Thanks again!

@caiokawasaki
Copy link
Author

@alucidwolf I did not store the tree in the Vuex of my application... Sorry, I do not know how to help you = /

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