[英]how to add script in html/jsx reactjs
I'm trying to add a style to a html element only when the property of an array of object has a certain value.仅当 object 数组的属性具有特定值时,我才尝试向 html 元素添加样式。 but I got an error like this instead:
但我得到了这样的错误:
/src/App.js: Unexpected token, expected "..." (35:25)
here's my code: codesandbox这是我的代码: codesandbox
export default function App() {
const data = [
{
id:1,
score:10,
},
{
id:2,
score:20,
},
{
id:3,
score:50,
}
];
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
{
data.length > 0
? (
<table>
<thead>
<tr>
<th>No.</th>
<th>value</th>
</tr>
</thead>
<tbody>
{
data.map((item, index) => (
<tr key={item.id}>
<td>{index+1}.</td>
<td {item.value > 10 ? 'style=\'backgroundColor:"red"\'' : ''}>
{item.value}
</td>
</tr>
))
}
</tbody>
</table>
)
: (
<div>
<em>No data</em>
</div>
)
}
{
data.map((item, index) => (
))
}
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.