尝试将视图嵌套到文本中时出现反应本机Android错误
我正在用react native开发一款iphone/android应用程序,它可以在表格中显示天气。为了创建表,我为react native:找到了这个表布局库,并在代码中使用了它。对于表中的一个数据行,我还希望显示天气的动态svg文件,因此我使用了以下库:。我的代码发布在下面:尝试将视图嵌套到文本中时出现反应本机Android错误,android,reactjs,svg,react-native,Android,Reactjs,Svg,React Native,我正在用react native开发一款iphone/android应用程序,它可以在表格中显示天气。为了创建表,我为react native:找到了这个表布局库,并在代码中使用了它。对于表中的一个数据行,我还希望显示天气的动态svg文件,因此我使用了以下库:。我的代码发布在下面: tableData = [["Weather" ,this.getIconForWeather(iconsWeather[0]), this.getIconForWeather(iconsWeather[1]), t
tableData = [["Weather" ,this.getIconForWeather(iconsWeather[0]), this.getIconForWeather(iconsWeather[1]), this.getIconForWeather(iconsWeather[2]), this.getIconForWeather(iconsWeather[3]), this.getIconForWeather(iconsWeather[4]), this.getIconForWeather(iconsWeather[5]), this.getIconForWeather(iconsWeather[6]), this.getIconForWeather(iconsWeather[7]), this.getIconForWeather(iconsWeather[8]), this.getIconForWeather(iconsWeather[9])],
["Temp", temp[0] + '°', temp[1]+ '°', temp[2]+ '°', temp[3]+ '°', temp[4]+ '°', temp[5]+ '°', temp[6]+ '°', temp[7]+ '°', temp[8]+ '°', temp[9]+ '°'],
["Precip" ,precip[0]+'%', precip[1]+'%', precip[2]+'%', precip[3]+'%', precip[4]+'%', precip[5]+'%', precip[6]+'%', precip[7]+'%', precip[8]+'%', precip[9]+'%'],
["Humidity" ,humidity[0]+'%', humidity[1]+'%', humidity[2]+'%', humidity[3]+'%', humidity[4]+'%', humidity[5]+'%', humidity[6]+'%', humidity[7]+'%', humidity[8]+'%', humidity[9]+'%'],
];
getIconForWeather(iconName) {
return <View style={{height: 40, width: 40, alignItems:'center', justifyContent:'center'}}>
<SVGImage
style={{ width: 40, height: 40, backgroundColor: 'transparent' }}
scrollEnabled = {false}
source={{uri: icons[iconName]}}
/>
</View>
}
//this is the part of the code in my return() in render() that displays the table:
<View style={styles.table}>
{/* Right scrollview wraper */}
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false}>
{/* If parent element is not table element, you should add the type of borderstyle. */}
<TableWraper borderStyle={{borderWidth: 1,borderColor: 'rgba(255,255,255,0.0)',}}>
<Row data={tableHead} style={styles.head} textStyle={styles.headText} widthArr={widthArr}/>
{
tableData.map((data, i) => (
<Row key={i} data={data} style={[styles.list, i%2 && {backgroundColor: 'rgba(255,255,255,0.0)'}]} widthArr={widthArr} textStyle={styles.listText}/>
))
}
</TableWraper>
</ScrollView>
</View>
react-react本机
组件仅支持iOS上的嵌套视图。您的第一个单元中的单元
组件使用
将传递的数据包装到表中,并且由于您正在为图像单元传递
,因此它不起作用
我想您可以尝试更改
组件以支持自定义渲染器
或者您可以按如下方式修改单元组件(第39行):
{typeof data=='object'
?{data]}
:{data}
如何自定义这样的单元组件?我是个新来的土生土长的人,我想我仍然需要包裹我的其他数据,比如温度,湿度,etc@ghost我已经用一种方法更新了响应,我将这段代码放在我的cell.js中,我得到了这个错误:/project/node_modules/react native table component/components/cell.js:Unexpected token,expected}(40:21)在cell.js:40:21中,我使用了以下代码:{typeof data==='object'?{data}:{data}},它工作了!!!这看起来对你来说合适吗,因为它在android上表现得很差,但那可能就是我的模拟器。非常感谢你的帮助,伙计!我收到一个警告,你知道怎么解决这个问题吗?它说:“为view.Bad Object提供的props.style键“0”无效。”它还告诉我一个错误,即为多个视图提供了键“0”。
for(let i = 0; i < days; i++){
await weatherBuildGUI.push(
<View key={i} style={styles.weatherDays}>
<View style={{flex:0.25, alignItems:'center', justifyContent:'center'}}>
<Text style={{fontWeight: 'bold', textAlign:'center'}}>{weatherHi[i]}</Text>
</View>
<View style={{flex:0.25, alignItems:'center', justifyContent:'center'}}>
<Text style={{textAlign:'center'}}>${weatherLo[i]}</Text>
</View>
<View style={{flex:0.25, alignItems:'center', justifyContent:'center'}}>
<Text style={{textAlign:'center', color:clr}}>{weatherDay[i]}</Text>
</View>
<View style={{flex:0.25, alignItems:'center', justifyContent:'center'}}>
<Text style={{textAlign:'center', color:clr}}>{weatherIcon[i]}</Text>
</View>
</View>
)
}
{typeof data === 'object'
? <View>{data]</View>}
: <Text style={[textStyle, styles.text]}>{data}</Text>}