如何从对象而不是"name"
中获得{item}
?
class Abc extends Component {
state = {
tags: [
{
"id": 1
"name": "goal"
},
{
"id": 2
"name": "kick"
}
]
}
render() {
return (
.................................
<div>
{this.state.tags.map((item, index) => (
<span key={index}>{item}</span>
))}
</div>
...................................
);
}
}
答案 0 :(得分:1)
只需直接访问它即可。
class Abc extends Component {
state = {
tags: [
{
"id": 1
"name": "goal"
},
{
"id": 2
"name": "kick"
}
]
}
render() {
return (
.................................
<div>
{this.state.tags.map((item, index) => (
<span key={item.id}>{item.name}</span>
))}
</div>
...................................
);
}
}