【发布时间】:2017-11-19 00:20:57
【问题描述】:
刚开始学习 React,当我点击提交按钮时,我不确定如何从我的文本字段中取回值。我在这里关注示例:https://material-ui-next.com/demos/dialogs/,但它们从未涵盖如何获取文本字段的值。我已经尝试了很多方法,但一直不确定价值。这是我当前的代码:
import React from 'react';
import ReactDOM from 'react-dom';
import Button from 'material-ui/Button';
import TextField from 'material-ui/TextField';
import { withStyles } from 'material-ui/styles';
import PropTypes from 'prop-types';
import Dialog, {
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
} from 'material-ui/Dialog';
import InsertLinkIcon from 'material-ui-icons/Link';
import ReactTooltip from 'react-tooltip'
import Icon from 'material-ui/Icon';
import IconButton from 'material-ui/IconButton';
const button = {
fontSize: '60px',
paddingRight: '20px',
paddingLeft: '20px',
}
const inlineStyle = {
display: 'inline-block',
}
export default class addTorrentPopup extends React.Component {
state = {
open: false,
};
handleClickOpen = () => {
this.setState({ open: true });
};
handleRequestClose = () => {
this.setState({ open: false });
};
handleSubmit = () => {
this.setState({ open: false });
let magnetLinkSubmit = this.state.textValue;
console.log("Sending magnet link: ", magnetLinkSubmit);
ws.send(magnetLinkSubmit);
}
render() {
const { classes, onRequestClose, handleRequestClose, handleSubmit } = this.props;
return (
<div style={inlineStyle}>
<IconButton onClick={this.handleClickOpen} color="primary" data-tip="Add Magnet Link" style={button} centerRipple aria-label="Add Magnet Link" >
<ReactTooltip place="top" type="light" effect="float" />
<InsertLinkIcon />
</IconButton>
<Dialog open={this.state.open} onRequestClose={this.handleRequestClose}>
<DialogTitle>Add Magnet Link</DialogTitle>
<DialogContent>
<DialogContentText>
Add a Magnet Link here and hit submit to add torrent...
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="name"
label="Magnet Link"
type="text"
placeholder="Enter Magnet Link Here"
fullWidth
/>
</DialogContent>
<DialogActions>
<Button onClick={this.handleRequestClose} color="primary">
Cancel
</Button>
<Button onClick={this.handleSubmit} color="primary">
Submit
</Button>
</DialogActions>
</Dialog>
</div>
);
}
};
【问题讨论】:
标签: javascript reactjs material-ui