需要在材料UI表中将按钮作为TableRowColumn放置的帮助! 我需要建立一个批准系统来批准或拒绝用户的请求。 我尝试以表格形式进行操作。我想在TableRowColumn中添加两个按钮“已批准”和“已拒绝”,如材料UI所给出的!
这里的代码是:
const usersToRequest = [
{ name: 'Rahul', phone: '1234567890', from: 'sunday', to: 'saturday', roomType: 'Single Room' },
{ name: 'Hari', phone: '9876554423', from: 'monday', to: 'sunday', roomType: 'Double Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
{ name: 'Rohit', phone: '0909090987', from: 'tuesday', to: 'monday', roomType: 'Twin Room' },
];
<TableBody displayRowCheckbox={false} stripedRows>
{
usersToRequest.map((utr, i) => (
i < 4 ? <TableRow key={i}>
<TableRowColumn>{i + 1}</TableRowColumn>
<TableRowColumn>{utr.name}</TableRowColumn>
<TableRowColumn>{utr.phone}</TableRowColumn>
<TableRowColumn>{utr.roomType}</TableRowColumn>
<TableRowColumn>{utr.from}</TableRowColumn>
<TableRowColumn>{utr.to}</TableRowColumn>
<TableRowColumn>
{
<RaisedButton label="Approved" primary={true} onClick={console.log("!23")}/>
<RaisedButton label="Rejected" secondary={true} onClick={console.log("!23")}/>
}
</TableRowColumn>
</TableRow> : ''
))
}
</TableBody>
我在此处添加的按钮无法正常工作!!!!
答案 0 :(得分:1)
您没有正确绑定事件处理程序: 试试这个:
<RaisedButton label="Approved" primary={true} onClick={()=>{console.log("!23")}}/>
<RaisedButton label="Rejected" secondary={true} onClick={()=>{console.log("!23")}}/>
答案 1 :(得分:1)
RaisedButton是一个自定义组件,您正在传递“ onClick”作为其道具。然后,您必须在子组件中接受prop并在父组件中定义click函数。此代码存储箱中的内容-https://codesandbox.io/s/6lp8vkyrnz
const handleClick = name => {
console.log(name);
};
<TableCell>
<RaisedButton click={() => handleClick(row.name)} />
</TableCell>
升高按钮
function RaisedButton(props) {
const { classes } = props;
return (
<Button variant="contained" onClick={props.click}>
Default
</Button>
);
}