我使用 React 和 Material UI 来显示一些映射的卡片。当我尝试扩展一张卡时,所有卡都会同时扩展。我发现我必须在“handleExpandClick”函数中传递一个索引,但仍然不起作用。也许我犯了某种错字。
我发现这个问题Expand one card on click涉及相同的问题,但似乎不适用于我的情况。
这是我的代码:
const useStyles = makeStyles(theme => ({
card: {
maxWidth: 345,
marginBottom: 15
},
media: {
height: 0,
paddingTop: "56.25%" // 16:9
},
expand: {
transform: "rotate(0deg)",
marginLeft: "auto",
transition: theme.transitions.create("transform", {
duration: theme.transitions.duration.shortest
})
},
expandOpen: {
transform: "rotate(180deg)"
},
avatar: {
width: 90
},
root: {
display: "flex",
justifyContent: "center",
flexWrap: "wrap",
"& > *": {
margin: theme.spacing(0.5)
}
},
list: {
width: 200
} …Run Code Online (Sandbox Code Playgroud)