【问题标题】:Vue.Js can not access Json-Data with a returned json key attribute as string - text template syntaxVue.Js can not access Json-Data with a returned json key attribute as string - text template syntax
【发布时间】:2022-12-02 12:31:15
【问题描述】:

I have the following data:

[...] 
 data() {
    return {
      theme: \"dark\",
      data: {
        ioa: [
          
          {
            title: \"xyz1\",
            applications: [\"app1\",\"app2\",\"app3\"],
          },

          {
            title: \"xyz2\",
            applications: [\"app1\",\"app2\"],
          },

        ],

        applications: {
          app1:{
            name: \"app1\",
          },
          mastodon:{
            app2: \"app2\",
          },
          app3:{
            name: \"app3\",
          },
        }
      }
    }
  },
[...]
<!--
First i loop thow the ioa array in data json object an print it with vues text template syntax
-->
<div v-for=\"item in data.ioa\">
    {{ item.title }}

<!--
for every element i will loop again throw the applications array in this object.
-->
    <div v-for=\"id in item.applications>

<!--
in \"id\" there is a specific name, that is also the json key of the application object in data. 
But when i want to print the title my application will show nothing
-->
        {{ data.applications.id.name }} 
    </div>
</div>

The Problem is that i can now access the \"application\" object, with the returned \"id\" in text template syntax

The browsers console says: \"Uncaught TypeError: data.applications.id is undefined\". I know there is a problem with \"id\" which is a string ... but i dont know how to solve this.

I want to get the value of \"application\" json object, based on the return id value from data.ioa json object

    标签: javascript vue.js


    【解决方案1】:
    猜你喜欢
    • 2017-03-03
    • 2022-12-02
    • 2022-11-20
    • 2015-12-20
    • 2022-12-01
    • 2022-12-01
    • 1970-01-01
    • 2016-05-06
    • 2022-11-20
    相关资源
    最近更新 更多