1

我減速機:無法顯示從Redux的狀況圖像ReactNative

const initialState = { 
    1: { 
    id: '1', 
    name: 'AryaStark', 
    theimage: "https://upload.wikimedia.org/wikipedia/en/3/39/Arya_Stark-Maisie_Williams.jpg" 
    }, 
    2: { 
    id: '2', 
    name: 'SansaStark', 
    theimage: "https://upload.wikimedia.org/wikipedia/en/7/74/SophieTurnerasSansaStark.jpg" 
    } 
} 

我能夠顯示內容的其餘部分,但不是圖像。我的代碼:

const renDataNew = Object.keys(this.props.newData).map((key, idx) => { 
    let data = this.props.newData[key] 
    return (
     <View key={idx} style={styles.myStyle1}> 
     <Text style={styles.myStyle2}>{data.id} - {data.name}</Text> 
     <Image 
     style={{width: '100%', height: 600}} 
     source={{uri:{data.theimage}}} //<= Error here expecting a , 
     /> 
     </View> 

如果我使用theimage的網址,直接在Image的URI源,它的工作原理。我究竟做錯了什麼?

什麼是顯示圖像的正確方法? 非常感謝。

回答

1

我覺得應該是:

<Image 
    style={{width: '100%', height: 600}} 
    source={{ uri: data.theimage }} 
/> 

你不需要額外{}各地data對象。

+0

非常感謝!這實際上工作。爲什麼我不需要'data.theimage'上的花括號? – Somename

+1

在例子中你正在創建無效的對象,它的語法錯誤。第二件事是[源代碼](https://facebook.github.io/react-native/docs/image.html#source)道具中的圖像將圖像源作爲String not Object接受。 – mradziwon