Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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/7/elixir/2.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 在react中单击按钮时如何关闭卡?_Reactjs_Material Ui - Fatal编程技术网

Reactjs 在react中单击按钮时如何关闭卡?

Reactjs 在react中单击按钮时如何关闭卡?,reactjs,material-ui,Reactjs,Material Ui,我有一个材料用户界面卡,其中包含图像、输入字段、复选框和提交按钮。在下面的代码中没有提到的其他选项上,卡显示onclick。我想在单击提交时关闭一张卡。我怎样才能做到这一点 <Card className="details-card" style={{ paddingTop: "0px" }} color="primary" > <CardHeader

我有一个材料用户界面卡,其中包含图像、输入字段、复选框和提交按钮。在下面的代码中没有提到的其他选项上,卡显示onclick。我想在单击提交时关闭一张卡。我怎样才能做到这一点

     <Card
          className="details-card"
          style={{ paddingTop: "0px" }}
          color="primary"
        >
          <CardHeader
            style={{
              paddingBottom: 0,
              paddingTop: 0
            }}
            title="Image"
          />
          <img src="https://unsplash.it/200/?random" />
          <CardContent className="details-card-body">
            <TextField label="Name" fullWidth />
            <Grid container>
              <Grid item xs={4}>
                <Typography>
                  New User
                  <Checkbox
                    checked={this.state.addNew}
                    name="addNew"
                    onChange={this.handleCheckBox("addNew")}
                    value="new user"
                    inputProps={{ "aria-label": "Checkbox B" }}
                  />
                </Typography>
              </Grid>
            </Grid>
            <Button variant="contained" color="primary">
              Click to Tag
            </Button>
          </CardContent>
        </Card>

新用户
单击以标记
下面是我在CodeSandbox上的代码

有多种方法可以实现您的目标 您需要一个标志来有条件地隐藏或显示卡。 例如,让我们在状态中使用
flag
变量,并基于提交按钮和您可以执行的
此.state.flag
更改状态变量
flag

{this.state.flag ?
    (<Card
        className="details-card"
        style={{ paddingTop: "0px" }}
        color="primary"
    >
        //Card content
    </Card>)
    :
    null
}

注意:不推荐第二种方法,因为我们正在渲染元素,即使它不是必需的。

有多种方法可以实现您想要做的事情 您需要一个标志来有条件地隐藏或显示卡。 例如,让我们在状态中使用
flag
变量,并基于提交按钮和您可以执行的
此.state.flag
更改状态变量
flag

{this.state.flag ?
    (<Card
        className="details-card"
        style={{ paddingTop: "0px" }}
        color="primary"
    >
        //Card content
    </Card>)
    :
    null
}
注意:不推荐第二种方法,因为我们正在渲染元素,即使它不是必需的