Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 根据阵列属性返回多个组件_Reactjs - Fatal编程技术网

Reactjs 根据阵列属性返回多个组件

Reactjs 根据阵列属性返回多个组件,reactjs,Reactjs,尝试从ActionButtons组件返回多个操作按钮: export default class ActionButtons extends Component { render() { console.log(this.props.actions) return( this.props.actions.map((field, i) => { <div key={field.href}> <DefaultBu

尝试从ActionButtons组件返回多个操作按钮:

export default class ActionButtons extends Component {
render() {
    console.log(this.props.actions)
    return(
    this.props.actions.map((field, i) => {
        <div key={field.href}>
            <DefaultButton
                key={field.href}
                text={field.label}
                href={field.href}
            />
        </div>
    })
    )
    }
}
导出默认类ActionButtons扩展组件{
render(){
console.log(this.props.actions)
返回(
this.props.actions.map((字段,i)=>{
})
)
}
}
使用以下代码从另一个组件调用它:

      const actions = [
            {"label": "Go Back", "href":"www.google.com"}
        ];
<ActionButtons actions={actions} />
const actions=[
{“label”:“返回”、“href”:“www.google.com”}
];

在ActionButtons组件上,如果我只返回一个按钮而没有映射,那么它就工作了。我缺少什么?

您需要从内部
map

//inside render
return this.props.actions.map((field, i) => {
    return (
        <div key={field.href}>
            <DefaultButton
                key={field.href}
                text={field.label}
                href={field.href}
            />
        </div>
    )
}
export default class ActionButtons extends Component {
    render() {
        console.log(this.props.actions)
        return (
            <>
            {
                this.props.actions.map((field, i) => {
                    return (
                        <div key={field.href}>
                            <DefaultButton
                                key={field.href}
                                text={field.label}
                                href={field.href}
                            />
                        </div>
                    )
                })
            }
            </>
        )
    }
}