【问题标题】:How to add "colSpan" attribute in ReactJS如何在 ReactJS 中添加“colSpan”属性
【发布时间】:2016-10-01 09:27:34
【问题描述】:

当我尝试将 colSpan="2" 属性添加到以下 ReactJS TypeScript 时,我收到错误“Type string is not assignable to type number”代码。我该如何解决这个问题?

class ProductCategoryRow extends React.Component<MyProps, MyState> {
   constructor(props: MyProps) {
      super(props);
   }
   render() {
      return (<div>
         <tr><th colSpan="2">{ this.props.category }</th></tr>
      </div>);
   } //end render.
} //end class.

【问题讨论】:

标签: reactjs typescript


【解决方案1】:

你试过&lt;th colSpan={2}&gt;{ this.props.category}&lt;/th&gt;吗?

【讨论】:

  • yes in HTML colspan="2" 在这里它就像字符串,而 colspan 应该像一个属性。所以在 React colspan 是 colSpan 并且对于“2”我们得到 {2} 这甚至不确定
猜你喜欢
  • 2020-12-26
  • 2021-11-25
  • 2021-03-13
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多