【问题标题】:How to display a span if the field have an information else no display with React JSX?如果字段有信息,如何显示跨度,否则 React JSX 不显示?
【发布时间】:2021-09-25 02:58:56
【问题描述】:

当字段不为空时我需要显示图标,否则我们会显示没有关闭图标的空字段

{
  this.state.showIcon ? (
    <span
      style={{ cursor: "pointer" }}
      onClick={() => {
        this.props.handleChangeAnyInput("", `exercice_${item.id}`);
      }}
    >
      X
    </span>
  ) : (
    ""
  );
}

【问题讨论】:

  • 您的代码是正确的,只需将) : ( "" ); 更改为) : ( &lt;span&gt;&lt;/span&gt; ); 以保留

    空格

  • 请回答
  • 嗨。 IMO 这不符合how to ask a good question 的标准。请添加预期的行为,以及您得到的结果。

标签: javascript reactjs jsx


【解决方案1】:

这是工作代码

{
            this.state.showIcon ? 
              <span
                style={{ cursor: "pointer" }}
                onClick={() => {
                  this.props.handleChangeAnyInput("", `exercice_${item.id}`);
                }}
              >
</span>
             : 
              ""
          }

【讨论】:

  • 非常感谢,但我也需要当字段有文件时,要关闭的图标存在
猜你喜欢
  • 1970-01-01
  • 2020-08-02
  • 1970-01-01
  • 2017-05-03
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-18
相关资源
最近更新 更多