首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Vue.Js不能使用返回的json键属性作为字符串-文本模板语法访问json-数据。

Vue.Js不能使用返回的json键属性作为字符串-文本模板语法访问json-数据。
EN

Stack Overflow用户
提问于 2022-12-01 09:11:47
回答 1查看 19关注 0票数 0

我有以下数据:

代码语言:javascript
运行
复制
[...] 
 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",
          },
        }
      }
    }
  },
[...]
代码语言:javascript
运行
复制
<!--
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>

问题是,我现在可以使用文本模板语法中返回的"id“访问"application”对象。

浏览器控制台上写着:“未定义的TypeError: data.applications.id”。我知道"id“是字符串有问题.但我不知道怎么解决这个问题。

我希望根据data.ioa json对象的返回id值获得"application“json对象的值。

EN

回答 1

Stack Overflow用户

发布于 2022-12-02 04:17:39

在v-for data.applications.id.name中,数据应该以id而不是调用。

在这里回答>>> 全答

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74639405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档