javascript - React Native - JSON对象的数组属性返回未定义,其他属性都返回一个值
问题描述
我对 React Native 很陌生,我正在努力弄清楚为什么我不能访问 JSON 对象的数组属性。
我的 JSON 对象如下所示:
{
"id": 1,
"items:": [
{
"description": "What is the current vehicle mileage?",
"id": 1,
"required": true,
"title": "Mileage",
"type": "Number"
},
{
"description": "First aid kid present?",
"id": 2,
"required": true,
"title": "Safety",
"type": "Boolean"
}
],
"title": "Default Inspection Report"
}
我正在使用的代码是:
import React from "react";
import { View, Text } from "react-native";
export default function VehicleInspection({ navigation, route }) {
console.log(route.params.template.items);
console.log(route.params.template);
return (
<View><Text>Title: {route.params.template.title}</Text></View>
);
}
如果我登录route.params.template
到控制台,它会返回包含“items”数组内容的整个对象。如果我登录route.params.template.items
到控制台,它会返回未定义。
在视图组件中返回route.params.template.title
按预期返回“默认检查报告”。
我在这里错过了一些非常愚蠢的东西吗?
这是上面代码的控制台输出:
undefined
Object {
"id": 1,
"items:": Array [
Object {
"description": "What is the current vehicle mileage?",
"id": 1,
"required": true,
"title": "Mileage",
"type": "Number",
},
Object {
"description": "First aid kid present?",
"id": 2,
"required": true,
"title": "Safety",
"type": "Boolean",
}
],
"title": "Default Inspection Report",
}
解决方案
推荐阅读
- .net - 集成测试:Microsoft.Owin.Selfhost 与 Microsoft.AspNet.TestHost(或 Selenium)?
- sql-server - 将生成的列添加到 SQL 查询结果的末尾
- python - 使用 Beautiful soup 在 HTML 表格中查找信息
- asp.net - 如何在 ASP.net Code.behind 中添加文本框列
- java - 多线程 Java 服务器,套接字异常错误
- android - 私有 IP 上的自签名 SSL 证书在 Chrome 中无效
- python - 基于字符串的Python类型转换
- assembly - 使用汇编读取输入(16 位引导加载程序)
- jsoup - Jsoup:从参展商列表中提取地址并存储在excel文件中
- typescript - 我应该在 Typescript 中重写所有现有的 jquery ajax webpart,还是在 SPFX 中注入现有的 jquery 更好?