gpt4 book ai didi

javascript - React 中的渲染对象属性

转载 作者:搜寻专家 更新时间:2023-11-01 05:28:26 26 4
gpt4 key购买 nike

我有一个这样的对象

export const otherInformation = [
{
"FAQ": ['Getting started guide', 'Selling policy'],
"Help & Support": ['Help guide', 'Selling policy'],
"Legal": ['Terms of Use', 'Privacy Policy']
}]

我的代码

class Information extends Component {
render() {
const otherInformationLoop = otherInformation.map((value, key) => {
return (
<div>
<div className="col-md-4" key={key}>
<div className="dashboard-info">

{Object.keys(value).map((val, k) => {
return (<h4 k={k}>{val}</h4>)
})
}

</div>
</div>
</div>
)
})

return (
{ otherInformationLoop }
// <div></div>
);
}
}

我在遍历对象时遇到问题。

得到的错误是这样的

Information.render():必须返回有效的 React 元素(或 null)。您可能返回了未定义、数组或其他一些无效对象

我怎样才能遍历对象以便获得所获得的结果

提前致谢。感谢任何帮助

最佳答案

你正在渲染一个数组,但你只能从你的 react 组件返回一个 block ,将你的 map 函数包装在一个 div 中

class Information extends Component {
render() {
const otherInformationLoop = otherInformation.map((value, key) => {
return (
<div>
<div className="col-md-4" key={key}>
<div className="dashboard-info">

{Object.keys(value).map((val, k) => {
return (<h4 k={k}>{val}</h4>)
})
}

</div>
</div>
</div>
)
})

return (

<div>{ otherInformationLoop }</div>
);
}
}

关于javascript - React 中的渲染对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43721168/

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