繁体   English   中英

如何在平面列表中打印图像组件? 反应本机

[英]How can I print image component inside a flatlist? REACT-NATIVE

我有这个对象:

 const new_note = {
                    note_number: last_note, //create a new_note object, note_number will be the key for each note
                    content: this.state.content, 
                    color: this.state.default_color, 
                    text_color: this.state.color, 
                    uri: this.uri,
                    real_content: clear_real_content,
                    images_uri: this.images_uri,
                }; 

其中 this.uri 是一个图像组件:

this.uri = <Image source = {{uri: clear_content}} style = {{width: 50, height: 50}}></Image>;

并将其打印在平面列表中:

                    <FlatList 
                        data = {this.props.array_notes} 
                        renderItem = {({item}) => (
                        <TouchableOpacity 
                            onLongPress = {() => this.show_hide_popup_menu(item)}
                            onPress = {() => this.select_edit(item)}
                            activeOpacity = {0.9}>
                            <View style = {this.styles.notes_container(dark, notes_backgroundColor, item)}>
                                {item.uri}
                            </View> 
                        </TouchableOpacity>)}
                        contentContainerStyle = {{flexGrow:1}}>
                    </FlatList>

但我收到此错误:

在此处输入图片说明

您只能在new_note对象中设置uri而不是Image元素。

const new_note = {
    note_number: last_note,
    content: this.state.content, 
    color: this.state.default_color, 
    text_color: this.state.color, 
    // uri: this.uri, <-- change this line as below
    uri: clear_content,
    real_content: clear_real_content,
    images_uri: this.images_uri,
};
      <FlatList 
          data = {this.props.array_notes} 
          renderItem = {({item}) => (
          <TouchableOpacity 
              onLongPress = {() => this.show_hide_popup_menu(item)}
              onPress = {() => this.select_edit(item)}
              activeOpacity = {0.9}>
              <View style = {this.styles.notes_container(dark, notes_backgroundColor, item)}>
                  <Image source={{ uri: item.uri }} style={{ width: 50, height: 50 }}/>
              </View> 
          </TouchableOpacity>)}
          contentContainerStyle = {{flexGrow:1}}>
      </FlatList>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM