我试图用react呈现一个属性对象列表,不幸的是它只是不呈现列表的内容。
import Property from "../Property"
import { Container } from "./StyledComponents"
const PropsList = (props) => {
const Properties = []
props.items.map(arrayElement => {
Properties.push(({key: arrayElement[0], value:arrayElement[1]}));});
return(
<Container>
{
Properties.map((element,index) => {
<Property key={index} field={element.key} value={element.value}>.
</Property>
})
}
</Container>
)
}
export default PropsList
代码的问题是您没有从映射返回任何内容。删除大括号,再试一次
import Property from "../Property"
import { Container } from "./StyledComponents"
const PropsList = (props) => {
const Properties = []
props.items.map(arrayElement => {
Properties.push(({key: arrayElement[0], value:arrayElement[1]}));});
return(
<Container>
{
Properties.map((element,index) =>
<Property key={index} field={element.key} value={element.value}>.
</Property>
)
}
</Container>
)
}
export default PropsList