React native react native中图像内部的动态URL

React native react native中图像内部的动态URL,react-native,React Native,我想问一下如何在react native中将动态URL实现到图像组件中。 图像的完整URL为: https://xxx.xxx.xx/image/journal/article?img_id=3551069&t=1518189123769 JSON对象是: { "announcements": [ { ... "photoUrl": "/image/journal/article?img_id=3551068&t=1518189123375", ...

我想问一下如何在react native中将动态URL实现到图像组件中。 图像的完整URL为:

https://xxx.xxx.xx/image/journal/article?img_id=3551069&t=1518189123769
JSON对象是:

{
    "announcements": [
        {
...
 "photoUrl": "/image/journal/article?img_id=3551068&t=1518189123375",
...
}
我使用带有renderItem的平面列表来迭代带有photoUrl列表的数组元素:

<List containerStyle={{ borderTopWidth: 0, borderBottomWidth: 0 }}>
          <FlatList containerStyle={ styles.card }

            data={this.state.announceData}
            renderItem={({ item }) => (
              <TouchableOpacity
              key = {item.articleId}
              // onPress={() => this.props.navigation.navigate('DrawerOpen')}
              style = {styles.card}>

              <View style={{ display: 'flex', flexDirection: 'row' }}>
              <View style={{width: '35%', height: '35%', position: 'relative', top: '15%'}}>
              <Image
              style= {{ height:50, width: 50 }}
              source={{uri:`https://xxx.xxx.xx${item.photoUrl}`}}
            />  
            </View>

            <View style={{width: '65%', flexWrap: 'wrap'}}>              
                <Text style={styles.annoucementTitle}>{item.title}</Text>
                <Text style={styles.annoucementSummary}>{item.summary}</Text>
                </View>
              </View>  
              </TouchableOpacity>
            )}

          />
           </List>

(
this.props.navigation.navigate('drawerropen')}
style={style.card}>
{item.title}
{项目摘要}
)}
/>

item.title
item.summary
正在加载,但图像不会加载。有人能提出可能的问题吗?我只是在对一款I-phone设备进行测试。这在Android设备中会有不同的表现吗?

尝试对图像路径进行硬编码,然后看看它是否有效。还要记录动态URI,看看它是否出了问题。我们使用正确的字符串插值格式,所以我猜这是路径本身的问题。祝你好运

我在这个问题上花了几个小时,但当我深入研究这个问题时,我发现,这是本地开发人员做出的设计决定。请在github上查看此问题。满足我需求的唯一实现如下所示:

const sampleImage= require("./assets/sample.png");
.....
....
...
export default {sampleImage}

然后在您想使用的地方导入此文件

谢谢您的回答,当我导入本地JSON文件时,似乎不会加载图像。但是,当我使用fetch从web服务获取相同的数据时,图像将最终加载!我忘了提到我使用EXPO作为设备测试仪。

您是否记录了整个url
https://xxx.xxx.xx${item.photoUrl}
&在浏览器中打开它以验证它是否为有效链接?