React:将参数传递给map中的函数

时间:2017-12-09 12:57:35

标签: javascript reactjs parameters map-function

我正在构建一个使用MaterialDesign表格在React中显示用户数组的组件。

Users Table  每一行都由地图函数生成:

let actions = this.props.rowButtons;
...
{this.props.tableData.map( (val, index) => (
                       <TableRow key={index}>
                         <TableRowColumn >{index}</TableRowColumn>
                         <TableRowColumn >{val.firstName}</TableRowColumn>
                         <TableRowColumn >{val.lastName}</TableRowColumn>
                         <TableRowColumn >{val.email}</TableRowColumn>
                         <TableRowColumn >
                            <ActionButtons actions={actions}/>
                         </TableRowColumn>
                       </TableRow>
))}

<ActionButtons>组件创建一个或多个按钮,并且作为参数获取对象数组,如[{type: string, onClick: function}, {type: string, onClick: function}, ... ](数组中每个对象一个按钮); 父组件正在 this.props.rowButtons 中发送此类数组。

我想将 val 作为参数传递给每个onClick函数,以便具有类似

的内容
actions = [{type: "personButton", onClick: onClick(val)}, {type: '', onclick: someOtherfunction(val)}]; 

1 个答案:

答案 0 :(得分:1)

您必须稍微修改getCategories(): Observable<Category[]> { return this.http.get<Category[]>(this.categoriesUrl).map((response)=>{ return response; }) } 。尝试按照以下方式进行。

actions
相关问题