【发布时间】: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.
【问题讨论】:
-
尝试
colSpan={2}- 您当前正在分配一个字符串值,要分配其他类型使用{并返回该值。可以是函数调用或文字或其他任何东西。例如colSpan={getColSpanSize()} -
@ctrlplusb - 谢谢,我相信这行得通。
标签: reactjs typescript