我在ReactNative ListView中显示存储在JSON数组中的图像时遇到问题 . 让我们说这是我的数据:
var data = [
{
id: 0,
photo: '../images/test.png',
},
{
id: 1,
photo: '../images/test.png',
},
{
id: 2,
photo: '../images/test.png',
},
]
然后,在我的课堂上,首先我需要数据(假设它正确导出):
var data = require("../data").data
然后,对于数据源中的每个元素,我遍历JSON数组,并尝试显示Image:
<Image source={{uri:item.photo}} style={styles.photo}></Image>
但是,屏幕上不显示任何内容 . 我知道数据正在被正确拉出,因为其他文本字段(上面未显示)显示正确,例如:
<Text style = {styles.name}>{item.id}</Text>
这显示正常 . 如果我试图直接在源中要求图像,即
<Image source={require('../images/test.png')} style={styles.photo}></Image>
它工作正常 . 有人知道为什么Image Source作为变量引用时没有拉动?
1 回答
你可以这样做: