2016-06-15 2 views
0

「メタデータ」オブジェクトをソースとして使用すると思われる反応のあるネイティブアプリケーションを構築しています。私は配列内の各オブジェクトを解析し、それぞれitemのJSXレイアウトを返します。私が持っている唯一の問題は、画像からソースを提供する方法です。なぜなら、それらはローカルに保存されており、require("link")にする必要があるからです。私のコードは私にエラーを与える:反応したネイティブのオブジェクトの解析された配列から画像ソースをレンダリングする

function loadModuleImplementation(moduleId, module) { 
    moduleId = "../../../images/icons/photographer/Party.png" 

マイコード:

class SelectScreen extends Component { 
    props:Props; 


    Details = [ 
     { 
      "type": "Party", 
      "image": "../../../images/icons/photographer/Party.png" 
     }, 
     { 
      "type": "Wedding", 
      "image": "../../../images/icons/photographer/Wedding.png" 
     }, 
     { 
      "type": "Architecture", 
      "image": "../../../images/icons/photographer/Arhitecture.png" 
     }, 
     { 
      "type": "Christening", 
      "image": "../../../images/icons/photographer/Christening.png" 
     } 
    ]; 

    render() { 
    let renderPhotoTypes =() => { 
     let type = []; 

     this.Details.map((item)=> { 
     type.push(
      <View style={styles.imageSelectItem} key={item.type}> 
      <TouchableWithoutFeedback> 
       <View> 
       <View style={styles.imageContainer}> 
        <Image style={styles.image} source={require(item.image)}/> 
       </View> 
       <Text style={styles.text}>{item.type}</Text> 
       </View> 
      </TouchableWithoutFeedback> 
      </View> 
     ); 
     }); 

     return type; 
    }; 

    return (
     <ScrollView style={styleGuide.containerMain}> 
     <Text style={styleGuide.heading_1}> 
      Select type 
     </Text> 

     <View style={styles.imageSelectContainer}> 
      {renderPhotoTypes()} 
     </View> 
     </ScrollView>); 
    } 
} 

バージョン:

"dependencies": { 
    "axios": "^0.12.0", 
    "babel-relay-plugin": "^0.9.0", 
    "buffer": "^4.6.0", 
    "color": "^0.11.1", 
    "invariant": "^2.2.1", 
    "react": "~15.0.2", 
    "react-native": "^0.26.1", 
    "react-native-button": "^1.6.0", 
    "react-native-drawer": "^2.2.3", 
    "react-native-fbsdk": "^0.2.1", 
    "react-native-message-bar": "^1.6.0", 
    "react-native-radio-buttons": "^0.11.0", 
    "react-native-vector-icons": "^2.0.3", 
    "react-redux": "^4.4.5", 
    "react-relay": "^0.9.0", 
    "redux": "^3.5.2", 
    "redux-logger": "^2.6.1", 
    "redux-persist": "^3.2.2", 
    "redux-thunk": "^2.1.0" 
    } 
+0

ような何かを行うことができますあなたは使っていますか?それはバージョン<0.14からアップグレードされましたか? –

+0

パッケージのバージョンを追加 – A1exandr

答えて

6

をあなたはネイティブの反応はどのバージョンのこの

Details = [ 
     { 
      type: "Party", 
      image: require("../../../images/icons/photographer/Party.png") 
     }, 
     { 
      type: "Wedding", 
      image: require("../../../images/icons/photographer/Wedding.png") 
     }, 
     { 
      type: "Architecture", 
      image: require("../../../images/icons/photographer/Arhitecture.png") 
     }, 
     { 
      type: "Christening", 
      image: require("../../../images/icons/photographer/Christening.png") 
     } 
    ]; 

    render() { 
    let renderPhotoTypes =() => { 
     let type = []; 

     this.Details.map((item)=> { 
     type.push(
      <View style={styles.imageSelectItem} key={item.type}> 
      <TouchableWithoutFeedback> 
       <View> 
       <View style={styles.imageContainer}> 
        <Image style={styles.image} source={item.image}/> 
       </View> 
       <Text style={styles.text}>{item.type}</Text> 
       </View> 
      </TouchableWithoutFeedback> 
      </View> 
     ); 
     }); 

     return type; 
    }; 
+0

正確に!どうもありがとう。 JSONスキーマのラッピング方法を今思う必要があります。 – A1exandr

+1

コールが静的に解析されバンドルされているため、イメージを動的にロードするのは実際には不可能です。 JSONスキーマを使用する場合は、イメージソースにuriプロパティを使用する必要があります。もう1つの回避策は、JSONスキーマの代わりにjavascriptオブジェクトを使用することです(別のモジュールに配置するだけです)。 –

+0

はい、おそらくソースとしての 'uri'はこのような状況になる方法です。 – A1exandr

関連する問題