第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在數(shù)組 React 組件中使用地圖打印 JSON 數(shù)據(jù)

如何在數(shù)組 React 組件中使用地圖打印 JSON 數(shù)據(jù)

狐的傳說(shuō) 2023-04-14 15:06:56
我在 React 數(shù)據(jù)文件中有一個(gè)這樣的數(shù)組,我正在使用該.map()方法在組件中加載 JSON 數(shù)據(jù)ProjectItem.js。打印嵌套 JSON 對(duì)象的最有效方法是什么?我現(xiàn)在想在項(xiàng)目數(shù)組中打印標(biāo)題,以便我可以調(diào)試它,在瀏覽器上顯示它。我在檢查員中看不到<div className="title"></div>,正確的功能是什么?數(shù)據(jù).json{"projects": [    {        "title": "Projecttitle1",        "category": "frontend development",        "description": "",        "desktop": [],        "mobile": []    }  ]}ProjectItem.jsimport React from 'react';import './ProjectItem.scss';import useWindowWidth from '../../Hooks/useWindowWidth.js';import { projects } from '../../data'import desktopImage from '../../Assets/Images/Projects/Desktop/123.jpg';import mobileImage from '../../Assets/Images/Projects/Mobile/123_square.jpg'const ProjectItem = ({ viewProject }) => {const imageUrl = useWindowWidth() >= 650 ? desktopImage : mobileImage;const { windowWidth } = useWindowWidth();return(    <div className="projectItem" style={{ backgroundImage: `url(${ imageUrl })`}}>        {windowWidth >= 650 &&(             <>            <div className="title">                {projects.map((data, key)=>{                        console.log(key);                    return(                        <div key={key}>                        {data.title}                        </div>                    );                })}             </div>            <div className="viewProject">{viewProject}</div>            </>        )}      </div>    );}; export default ProjectItem安慰:空的
查看完整描述

1 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊

我假設(shè)import { projects } from '../../data'是這樣的:


export const data = {

? projects: [

? ? {

? ? ? title: "Project title 1",

? ? ? category: "frontend development",

? ? ? description: "",

? ? ? desktop: [],

? ? ? mobile: []

? ? }

? ]

};


projects所以當(dāng)你映射這個(gè)對(duì)象時(shí),你需要像這樣引用屬性data.projects.map()。


例子:


數(shù)據(jù).js


export const data = {

? projects: [

? ? {

? ? ? title: "Project title 1",

? ? ? category: "frontend development",

? ? ? description: "",

? ? ? desktop: [],

? ? ? mobile: []

? ? },

? ? {

? ? ? title: "Project title 2",

? ? ? category: "frontend development",

? ? ? description: "",

? ? ? desktop: [],

? ? ? mobile: []

? ? }

? ]

};


應(yīng)用程序.js


import React from "react";


import { data } from "./data";


export default function App() {

? return (

? ? <div>

? ? ? {data.projects.map((project, key) => {

? ? ? ? return <p key={key}>{project.title}</p>;

? ? ? })}

? ? </div>

? );

}


查看完整回答
反對(duì) 回復(fù) 2023-04-14
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)