<v-app>
<v-treeview :items="items">
<template slot="append" slot-scope="{ item }">
<v-btn @click="addChild(item);">Add child</v-btn>
</template>
</v-treeview>
</v-app>
addChild(item) {
if (!item.children) {
this.$set(item, "children", []);
}
const name = `${item.name} (${item.children.length})`;
const id = this.nextId++;
item.children.push({
id,
name
});
}
findItem(id, items = null) {
if (!items) {
items = this.items;
}
return items.reduce((acc, item) => {
if (acc) {
return acc;
}
if (item.id === id) {
return item;
}
if (item.children) {
return this.findItem(id, item.children);
}
return acc;
}, null);
}
<v-app>
<v-treeview :items="items">
<template slot="append" slot-scope="{ item }">
<v-btn @click="addChild(item);">Add child</v-btn>
</template>
</v-treeview>
</v-app>
addChild(item) {
if (!item.children) {
this.$set(item, "children", []);
}
const name = `${item.name} (${item.children.length})`;
const id = this.nextId++;
item.children.push({
id,
name
});
}
findItem(id, items = null) {
if (!items) {
items = this.items;
}
return items.reduce((acc, item) => {
if (acc) {
return acc;
}
if (item.id === id) {
return item;
}
if (item.children) {
return this.findItem(id, item.children);
}
return acc;
}, null);
}