gpt4 book ai didi

javascript - 我的应用程序中的箭头功能出现问题

转载 作者:行者123 更新时间:2023-12-02 23:48:09 25 4
gpt4 key购买 nike

一切正常,直到我添加初始玩家。 map 箭头功能步骤在第 52 行(玩家列表评论)上实现。记分板应该使用玩家的数组显示其下方的名称值,当我使用开发工具检查元素时,所有内容都会显示出来,直到这一步,也许这是我观看视频 5 次时没有发现的内容。

以下是该网站的链接:https://codingoni.github.io/React-Project/代码链接:https://github.com/CodingOni/React-Project

我多次尝试检查语法

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scoreboard</title>
<link rel="stylesheet" href="./app.css" />
</head>

<body>
<div id="root"></div>

<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel" src="app.js"></script>
</body>
</html>


const players = [
{
name: "Guil",
score: 50
},
{
name: "Treasure",
score: 85
},
{
name: "Ashley",
score: 95
},
{
name: "James",
score: 80
}
];
const Header = (props) => {
return(
<header>
<h1>{props.title}</h1>
<span className="stats">Player: {props.totalPlayers} </span>
</header>
);
}


const Player = (props) => {
return( <div className="player">
<span className="player-name"> {props.name} </span>
<Counter score={props.score} />
</div>
);
}


const Counter = (props) => {
return( <div className="counter">
<button className="counter-action decrement">-</button>
<span className="counter-score">{props.score}</span>
<button className="counter-action increment">+</button>
</div>
);
}

const App = (props) =>{
return(
<div className="scoreboard">
<Header title="Scoreboard" totalPlayers={"1"}/>
// {Players List*/}
{props.initialPlayers.map( player =>
<Player
name={player.name}
score={player.score}
/>
)}

<Player name="Tyrique" score={20} />
<Player name="Tyrique" score={30} />
<Player name="Tyrique" score={10} />
<Player name="Tyrique" score={15} />

</div> ); }

ReactDOM.render(
<App initialPlayers={players} />,
document.getElementById('root') );

显示在板上的姓名和分数

最佳答案

也许可以尝试一下:

{props.initialPlayers.map( (player, index) => {
return <Player
key={index}
name={player.name}
score={player.score}
/>
})}

关于javascript - 我的应用程序中的箭头功能出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55754780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com