phphe / vue-draggable-nested-tree

Vue2 draggable tree component
https://hetree.phphe.com/
MIT License
345 stars 62 forks source link

How to click the node to get the data of each node in the development scenario #61

Open zhanjunhao opened 5 years ago

zhanjunhao commented 5 years ago

So let's say I want to click and get the data for each node how do I extend that by just adding the click event

phphe commented 5 years ago
Tree(:data="data" draggable crossTree)
  div(slot-scope="{data, store, vm}" @click="yourmethod(data)")
    //- data is node
    //- store is the tree
    //- vm is node Vue instance, you can get node level by vm.level
    template(v-if="!data.isDragPlaceHolder")
      b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} 
      span {{data.text}}
zhanjunhao commented 5 years ago

thank you I see 😄

zhanjunhao commented 5 years ago

那个 添加了@click="yourmethod(data)" 获取当前节点数据 时 我想解析当前节点的数据 但是该对象 还在遍历循环中 控制台报错:Uncaught TypeError: Converting circular structure to JSON

phphe commented 5 years ago

那个 添加了@click="yourmethod(data)" 获取当前节点数据 时 我想解析当前节点的数据 但是该对象 还在遍历循环中 控制台报错:Uncaught TypeError: Converting circular structure to JSON use tree.pure

// with children
div(slot-scope="{data, store, vm}" @click="yourmethod(store.pure(data, true))")
// without children
div(slot-scope="{data, store, vm}" @click="yourmethod(store.pure(data))")
zhanjunhao commented 5 years ago

ok, you are good!

zhanjunhao commented 5 years ago

Tree events change Event the third parameter oldTree returns null and does not fetch the oldTree structure

phphe commented 5 years ago

Tree events change Event the third parameter oldTree returns null and does not fetch the oldTree structure

old tree exists when drag cross tree

zhanjunhao commented 5 years ago

What kind of situation is the existence of the old tree can not try out

phphe commented 5 years ago

https://github.com/phphe/vue-draggable-nested-tree/blob/master/src/components/DraggableTreeNode.vue#L61 check the source code, line 61 to 68

zhanjunhao commented 5 years ago

O I see