【问题标题】:Passing parent ID in Vuetify's treeview component to function在 Vuetify 的树视图组件中传递父 ID 以运行
【发布时间】:2019-03-11 08:27:36
【问题描述】:

我正在尝试使用 Vuetify 的 Treeview 来显示作物病害诊断键。 Treeview 提供了一个道具“load-children”,如果正在展开的项目的 item-children 属性是一个空数组,则该道具会运行一个函数。

如何修改它以将父级的 id 传递给函数?在树中的这一点上,我们将到达键控病原体 - 我想将其 ID(例如下面数据中的 ids 333、666、999)传递给一个函数,以便在单击该病原体时加载有关该病原体的附加资源。

我的一组典型数据(以及 Vuetify 的演示函数“fetchUsers”)如下:

export default {
    name: "key",
    data() {
        return {
          active: [],
          items: [
            {
              id: 1,
              name: 'Roots :',
              children: [
                { id: 2,
                  name: 'Seedlings',
                  children: [
                    {   id: 123,
                        name: 'Watery rot in root/stem near the soil line',
                        children: [
                          {id:333,name: 'Damping off',children: []}
                        ]}
                  ]},
                { id: 3,
                  name: 'Larger plants',
                  children: [
                    {id:124, name: 'Brown, sunken lesions near soil-line', children: [
                        {id:666,name: 'Rhizoctonia root rot',children: []}
                      ]},
                    {id:125, name: 'Soft wet rot at base of stem extending to roots', children: [
                        {id:999,name: 'Bacterial soft rot',children: []}
                      ]}
                  ]},
              ]
            },
          ]
        }
    },
    methods: {
      async fetchUsers (item) {
        return fetch('https://jsonplaceholder.typicode.com/users')
          .then(res => res.json())
          .then(json => (item.children.push(...json)))
          .catch(err => console.warn(err))
      },
    }
}

我使用的模板是

<v-treeview
:items="items"
:active.sync="active"
:load-children="fetchUsers"
activatable
open-on-click
transition

也许该信息已在 fetchUsers(item) 中传递 - 如果是这种情况,那么我该如何读取该信息?到目前为止我的尝试,例如

methods: {
      async fetchUsers (item) {
        console.log('item='+item[0].id);

已触发有关“无法读取未定义的属性 'id' 的错误。

谢谢,汤姆。

【问题讨论】:

    标签: vuetify.js


    【解决方案1】:

    我需要的信息在“item”中传递 - item.id 给了我,而不是 item[0].id!

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2011-07-31
      相关资源
      最近更新 更多