下面是我的 react 组件的一部分。我有一个名为 daysUntil 的 Prop 进入这个包含数字的组件。在此示例中,它传递了数字 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;
}
我收到以下错误:
JSON value '700' of type NSNumber cannot be converted to NSSTring.
我假设这是因为 font-weight 期望值是字符串格式。什么是正确的解决方法?
提前致谢!
最佳答案
在你的 fontWeight() 函数中
return weight * 100;
可能会变成:
var val= weight * 100;
return val.toString();
关于ios - React Native - NSNumber 无法转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640369/