下面是我的反应组件的一部分。我有一个名为 daysUntil 的道具进入这个包含一个数字的组件。在此示例中,它传递数字 0,这导致 fontWeight 函数返回 700
render: function() {
return (
<Text style={this.style()}>
{this.props.day}
</Text>
)
},
style: function() {
return {
fontWeight: this.fontWeight()
}
},
fontWeight: function() {
var weight = 7 - this.props.daysUntil;
return weight * 100;
}
我收到以下错误:
NSNumber 类型的 JSON 值“700”无法转换为 NSSTring。
我假设这是因为 font-weight 期望值是字符串格式。什么是正确的解决方法?
先感谢您!
原文由 Sohrab Hejazi 发布,翻译遵循 CC BY-SA 4.0 许可协议
在你的 fontWeight() 函数中
可能变成: