我在本地有大约100个英雄的图像,需要导入到列表视图中.这是我的hero.js
renderRow(hero) {
return (
<View>
<View style={styles.container}>
<Image
source={require('./img/hero/'+hero.img+'.jpg')}
style={styles.thumbnail} />
<View style={styles.rightContainer}>
<Text style={styles.title}>{hero.name}</Text>
</View>
</View>
<View style={styles.separator} />
</View>
);
经过一些研究,我知道要求不允许动态名称.我也试过uri,没有错误,但也没有图像.
{{uri: './img/hero/'+hero.img+'.jpg'}}
我的文件夹结构是这样的:
Project
index.ios.js
hero.js
img
hero
处理此问题的最佳方法是什么,我不想将图像放在网络上.
解决方法:
萨伦斯在这个forum上说了以下内容
We intentionally don’t support dynamically generated image names because it makes it very hard to manage assets over time, just like how you wouldn’t want to do
看起来它可以通过uri完成,但它需要一些工作.你需要在xcode资产中添加你的图像,在res / drawable下添加你的android.
然后,您可以使用< Image source = {{uri:“image”“name”}} />获取您的图片.