首页 > 解决方案 > 返回内部功能组件中的显示值

问题描述

我尝试从对象中填充值

我的对象

{ 
    "title": 5
    "value": 6
    "second": "2019-03-06" 
}

我的渲染部分。它在地图和 foreach 中都显示错误

{newAttributes.forEach((data) => {
            <React.Fragment>
                 
                    <label > {data.title} </label>
                 
                    <label  >{data.value} -</label>
                 
                    <label  > {data.second} </label>
                 
            </React.Fragment>
             
             })}    

在地图中,我尝试了除键之外的其他值,我无法获得其他值

{Object.keys(newAttributes).map((key) => ( 

<React.Fragment>
                     
                        <label > {newAttributes.title} </label>
                     
                        <label  >{newAttributes.value} -</label>
                     
                        <label  > {newAttributes.second} </label>
                     
                </React.Fragment>
                 
                 ))}

标签: reactjs

解决方案


我猜你错过了从地图返回一个值以及你访问属性的方式

{
    Object.keys(newAttributes).map((data) => {
        return <label> {newAttributes[key]} </label>
   })
} 

例子


推荐阅读