Render images sources from parsed array of objects in react native

后端 未结 1 1490
既然无缘
既然无缘 2021-01-28 05:31

I\'m building a react native application which suppose to use some \'meta-data\' objects as sources. I\'m parsing each object in array and returning a JSX layout for each

相关标签:
1条回答
  • 2021-01-28 06:03

    You can do something like this

      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 讨论(0)
提交回复
热议问题