Soh*_*azi 10 nsnumber nsstring ios reactjs react-native
以下是我的反应组件的一部分.我有一个名为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;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
NSNumber类型的JSON值'700'无法转换为NSSTring.
我假设这是因为font-weight期望值为字符串格式.对此有什么正确的解决方法?
先感谢您!
Rob*_*kal 17
在你的fontWeight()函数中
return weight * 100;
Run Code Online (Sandbox Code Playgroud)
也许变成:
var val= weight * 100;
return val.toString();
Run Code Online (Sandbox Code Playgroud)
我有一个类似的问题,我正在将图标而不是uri传递给Image。该代码被编写为接受icon = 'path/to/icon':
<Image source={{ uri: icon }}>
Run Code Online (Sandbox Code Playgroud)
但我正在传递icon = require('path/to/icon'),我不得不将jsx切换为
<Image source={icon}>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17999 次 |
| 最近记录: |