简体   繁体   English

Vue.js树形视图与来自AJAX调用的数据

[英]Vue.js tree view with data from AJAX call

So I'm just starting to play with Vue.js and was trying to get the tree view from Vue.js working. 因此,我刚刚开始使用Vue.js,并试图从Vue.js中获取树状视图。

Fetching the data with an AJAX call and displying it is working great. 通过AJAX调用获取数据并显示该数据非常有效。

Here's my problem: I cant figure out how to show/hide elemnts. 这是我的问题:我不知道如何显示/隐藏要素。 I was trying to do it the same way as it is shown on the Vue seie: see here All i'm getting is one "open" variable, and not for each category one. 我试图以与Vue seie上显示的方式相同的方式执行此操作: 请参阅此处,我所得到的只是一个“开放”变量,而不是针对每个类别。 Of course every time i toggle it all items are shown/hidden. 当然,每次我切换它时,所有项目都会显示/隐藏。

I hope this makes it clear: 我希望这可以使您清楚:

{
  "open": false,
  "list": {
        "categories": [
          {
            "id": 1,
            "name": "Some Category",
            "created_at": "2015-12-31 10:10:58",
            "updated_at": "-0001-11-30 00:00:00",
            "items": [
              {
                "id": 1,
                "category_id": 1,
                "name": "Some Item",
                "description": "Lorem",
                "price": 10,
                "created_at": "2015-12-31 10:11:45",
                "updated_at": "-0001-11-30 00:00:00"
              },
              {
                "id": 8,
                "category_id": 1,
                "name": "Some Item",
                "description": "Lorem",
                "price": 10,
                "created_at": "2015-12-31 11:56:44",
                "updated_at": "2015-12-31 11:56:44"
              },
              {
                "id": 32,
                "category_id": 1,
                "name": "aa",
                "description": "        \r\n    ",
                "price": 122,
                "created_at": "2016-01-07 14:46:43",
                "updated_at": "2016-01-07 14:46:43"
              }
            ]
          },
          {
            "id": 2,
            "name": "Some Category",
            "created_at": "2015-12-31 10:10:58",
            "updated_at": "-0001-11-30 00:00:00",
            "items": [
              {
                "id": 2,
                "category_id": 2,
                "name": "Some Item",
                "description": "Lorem",
                "price": 30,
                "created_at": "2015-12-31 10:11:45",
                "updated_at": "-0001-11-30 00:00:00"
              },
              {
                "id": 3,
                "category_id": 2,
                "name": "Some Item",
                "description": "Lorem",
                "price": 20,
                "created_at": "2015-12-31 10:13:06",
                "updated_at": "-0001-11-30 00:00:00"
              }
            ]
        }
     ]
  }
}

I spend the whole day trying to figure this out... 我整天都在努力解决这个问题...

Thanks in advance for your help! 在此先感谢您的帮助!

Finally got Vue.set working: 终于让Vue.set工作了:

toggle: function (category) {
    if(! category.open)
    {
        Vue.set(category, 'open' , false)
    }
    category.open = !category.open
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM