【发布时间】:2020-09-05 13:11:16
【问题描述】:
我正在尝试向我的平面列表的每个键添加不同的图像。但是,通过渲染项目,图像并没有显示在屏幕上,只是键。图片的来源是正确的,图片的名称也是正确的。你能找出我犯的错误吗?
export default class HomeScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
searchText: '',
};
}
render() {
//Data can be coming from props or any other source as well
const data = [
{
key: 'Tiago',
logo: '../assets/athlean_x.png'
},
{
key: 'Beatriz',
logo: "euro2020.png"
},
{
key: 'Ricardo',
logo: "jamor.png"
},
{
key: 'Miguel',
logo: "rock_in_rio.png"
},
{
key: 'Simão',
logo: "splash.png"
},
{
key: 'David',
logo: "edp_cooljazz.png"
}
];
const filteredData = this.state.searchText
? data.filter(x =>
x.key.toLowerCase().includes(this.state.searchText.toLowerCase())
)
: data;
return (
<View style={styles.container}>
<View style={styles.flatlist}>
<FlatList
data={filteredData}
renderItem={({ item }) => (
<View style={{flexDirection:'row'}}>
<Image
style={{width:50, height:50, alignSelf: 'center', borderRadius:300}}
source={{uri:item.logo}}/>
<Text style={styles.item}>{item.key}</Text>
</View>
)}
/>
</View>
</View>
);
}
【问题讨论】:
标签: reactjs image react-native react-native-flatlist