[英]How can I get the contents of all elements with a specific parent class in jQuery and pass them in a GET variable?
[英]How to get id of a specific tree node when I click on them and then pass that data into my variable
我是Quasar和Vue的新手。 有人可以向我解释如何解决我的任务吗?
简要介绍一下任务:
(1)我有一个q树元素,它表示屏幕左侧的文件夹结构[ref.1]
(2)这是文件夹结构[ref.2]
(3)当用户单击此文件夹结构中的任何元素时,他将在右侧看到一个新组件,在网格布局中,该组件具有被单击的所有子元素。
这就是我现在所拥有的。
[ref.1] treeComponent.vue
<template> <q-tree :nodes="documents" @click="getId" node-key="id" > </q-tree> </template> <script> var documents = require('./documents') module.exports = { data: function () { return { selectedDoc: x, documents: documents } }, methods: { getId: function () { const x = this.getNodeByKey('id') consol.log(x) } } } </script>
[ref.2] documents.js
module.exports = [ { id: '1', label: 'My Documents', icon: 'folder', children: [ { id: '01', label: 'Dir 1', children: [ { id: '0001', label: 'Doc 1'}, { id: '0002', label: 'Doc 2'} ] }, { id: '02', label: 'Dir 2', children: [ { id: '0003', label: 'Doc 3'}, { id: '0004', label: 'Doc 4'} ] }, { id: '103', label: 'Dir 3', children: [ { id: '0005', label: 'Doc 5'}, { id: '0006', label: 'Doc 6'}, { id: '0007', label: 'Doc 7'} ] } ] } ]
您需要用key替换id。此操作之后为每个节点添加此处理程序
handler: (node) => this.onclick(node)
然后在方法中添加此方法
onclick(node) {
alert(node.key)
},
这将显示垂直节点的ID
因此,主要问题与对Quasar框架的了解不够充分有关。 这是我对这个问题的回答:
<template>
<button v-on:click = "showNodeSelected">showClickedNode</button>
<q-tree
:nodes = "documents"
:selected.sync = "selected"
node-key="id"
/>
</template>
<script>
var documents = require('./documents')
module.exports = {
data: function () {
return {
selected: null,
documents: documents
}
},
methods: {
showNodeSelected: function () {
console.log(this.selected)
}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.