Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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
Javascript TextField和Select不变-React JS_Javascript_Reactjs_React Redux_Material Ui - Fatal编程技术网

Javascript TextField和Select不变-React JS

Javascript TextField和Select不变-React JS,javascript,reactjs,react-redux,material-ui,Javascript,Reactjs,React Redux,Material Ui,我是全新的全栈开发人员,我正在尝试编写一些代码,以便更好地理解React JS前端。我也使用过redux,但从未出现过错误。我一直在尝试从firebase文档中编写一个字段列表,我可以根据已知数据修改这些字段并将其发送回服务器。但每个TextField和Select不会更改其值: class PostDialog extends Component { state = { open: false, oldPath: '', newPath: '', Code:

我是全新的全栈开发人员,我正在尝试编写一些代码,以便更好地理解React JS前端。我也使用过redux,但从未出现过错误。我一直在尝试从firebase文档中编写一个字段列表,我可以根据已知数据修改这些字段并将其发送回服务器。但每个TextField和Select不会更改其值:

class PostDialog extends Component {
  state = {
    open: false,
    oldPath: '',
    newPath: '',
    Code:"",
    barrCode:"",
    color:"",
    size:"",
    qnt:"",
    brand:"",
    cat:"",
    price:"",
    createdAt:"",
    descr:"",
    errors:{}
  };
  componentDidMount() {
    if (this.props.openDialog) {
      this.handleOpen();
    }
  }
  handleOpen = () => {
    let oldPath = window.location.pathname;

    const { userHandle, postId } = this.props;
    const newPath = `/inv/${postId}`;

    if (oldPath === newPath) oldPath = `/inv`;

    window.history.pushState(null, null, newPath);

    
    this.props.getPost(this.props.postId);
    this.setState({ open: true, oldPath, newPath, size: this.props.size });
  };
  handleClose = () => {
    window.history.pushState(null, null, this.state.oldPath);
    this.setState({ open: false });
    this.props.clearErrors();
  };

  handleChange=(event)=>{
    this.setState({[event.target.name]: event.target.value})
  };
  onTodoChange(value){
    this.setState({
      barrCode: value
    });
}
  render() {
    const {errors} = this.state;
    const {
      classes,
      post: {
        postId,
        Code, barrCode, color,size,qnt,brand,cat,price,createdAt,descr,available
      },
      UI: { loading }
    } = this.props;


    const ITEM_HEIGHT = 48;
        const ITEM_PADDING_TOP = 8;
        const MenuProps = {
            PaperProps: {
              style: {
                maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
                width: 250,
              },
            },
        };

    const dialogMarkup = loading ? (
      <div className={classes.spinnerDiv}>
        <CircularProgress size={200} thickness={2} />
      </div>
    ) : (
      <Grid container spacing={16}>
        <Grid item sm={7}>
          <hr className={classes.invisibleSeparator} />
          <Typography variant="body2" color="textSecondary">
            {dayjs(createdAt).format('h:mm a, MMMM DD YYYY')}
          </Typography>
          <hr className={classes.invisibleSeparator} />
          <TextField
                                name="barrCode"
                                type="text"
                                label="Codice a Barre"
                                placeholder="111111111"
                                rows="1"
                                error={errors.barrCode ? true : false}
                                helperText={errors.barrCode}
                                className={classes.TextField}
                                value={barrCode}
                                onChange={this.handleChange}
                                fullWidth
                            />
                            <TextField
                                name="price"
                                type="text"
                                label="Prezzo"
                                placeholder="111111111"
                                rows="1"
                                error={errors.price ? true : false}
                                helperText={errors.price}
                                className={classes.TextField}
                                value={price}
                                onChange={this.handleChangePrice}
                                fullWidth
                            />
                            <Box display="flex" flexDirection="row">
                              <Box>
                              <InputLabel id="brand">Marca</InputLabel>
                                        <Select
                                            labelId="Marca"
                                            id="brand"
                                            value={brand}
                                            onChange={this.brandChange}
                                            input={<Input />}
                                            MenuProps={MenuProps}
                                        >
                                        {brands.map((brand) => (
                                            <MenuItem value={brand}>
                                            {brand}
                                            </MenuItem>
                                        ))}
                                        </Select>
                              </Box>
                              <Box>
                              <InputLabel id="cat">Categoria</InputLabel>
                                        <Select
                                            labelId="Marca"
                                            id="cat"
                                            value={cat}
                                            onChange={this.catChange}
                                            input={<Input />}
                                            MenuProps={MenuProps}
                                        >
                                        {cats.map((cat) => (
                                            <MenuItem value={cat}>
                                            {cat}
                                            </MenuItem>
                                        ))}
                                        </Select>
                              </Box>
                              
                            </Box>
                            
                             
        </Grid>
        <hr className={classes.visibleSeparator} />
        <DeletePost postId={postId} />
          {/* <CommentForm postId={postId} /> */}
          {/* <Comments comments={comments} />  */}
      </Grid>
    );
    return (
      <Fragment>
        <MyButton
          onClick={this.handleOpen}
          tip="Modifica"
          tipClassName={classes.expandButton}
        >
          <UnfoldMore color="primary" />
        </MyButton>
        <Dialog
          open={this.state.open}
          onClose={this.handleClose}
          fullWidth
          maxWidth="sm"
        >
          <MyButton
            tip="Close"
            onClick={this.handleClose}
            tipClassName={classes.closeButton}
          >
            <CloseIcon />
          </MyButton>
          <DialogContent className={classes.dialogContent}>
            {dialogMarkup}
          </DialogContent>
        </Dialog>
      </Fragment>
    );
  }
}

PostDialog.propTypes = {
  clearErrors: PropTypes.func.isRequired,
  getPost: PropTypes.func.isRequired,
  postId: PropTypes.string.isRequired,
  post: PropTypes.object.isRequired,
  UI: PropTypes.object.isRequired
};

const mapStateToProps = (state) => ({
  post: state.data.post,
  UI: state.UI
});

const mapActionsToProps = {
  getPost,
  clearErrors
};

export default connect(
  mapStateToProps,
  mapActionsToProps
)(withStyles(styles)(PostDialog));

我不知道如何解决这个问题,我能做什么?

试试这个

handleChange=事件=>{ this.setState{…this.state,event.target.name:event.target.value}; }; 编辑 还要将html输入中的值更改为value={this.state.[somevalue]}


它给了我语法错误,错误说什么,在哪里?语法错误;意料之中,我想我错过了一次;在该行末尾,您遗漏了变量属性名称周围的括号,它应该是{…this.state,[event.target.name]:event.target.value}