Javascript 如何在按React native中的一个Swipout按钮时将值传递给其他屏幕?

Javascript 如何在按React native中的一个Swipout按钮时将值传递给其他屏幕?,javascript,react-native,Javascript,React Native,在我的React原生项目中,我在一个类中声明了按钮-在Swipout中编辑和删除按钮,我将其用于渲染平面列表的项目。这是我的整个renderItem函数的代码,其中包含Swipout按钮- renderItem = ({item}) => { let a = this.getStatusIcon(item.category); console.log(a); let swipeBtns = [{ text: 'Edit', back

在我的React原生项目中,我在一个类中声明了按钮-在Swipout中编辑和删除按钮,我将其用于渲染平面列表的项目。这是我的整个renderItem函数的代码,其中包含Swipout按钮-

    renderItem = ({item}) => {
    let a = this.getStatusIcon(item.category);
    console.log(a);

    let swipeBtns = [{
      text: 'Edit',
      backgroundColor: 'green',
      underlayColor: 'rgba(0, 0, 0, 1, 0.6)',
      onPress: () => this.props.navigation.navigate('UpdateNotes',
      NOTE_ID = item.id,
      ),
      autoClose: true
    },

    {
      text: 'Delete',
      backgroundColor: 'red',
      underlayColor: 'rgba(0, 0, 0, 1, 0.6)',
      onPress: () => { this.delete(item.id) },
      autoClose: true
    }

  ];

    return(

      <Swipeout right={swipeBtns}
      backgroundColor= 'transparent'>

      <TouchableOpacity style={styles.container}
      onPress={() => this.props.navigation.navigate('DetailsNote', {
        JSON_ListView_Clicked_Item: item.id,
      })}
          >


        <View style={{width:'100%'}}>

            <Text style={{ textAlign:'right', marginRight:10}}>{item.timestamp}</Text>

        <View style={{flex:1, flexDirection:'row'}}>

        <Image style={{width:50, height:50, marginLeft:10, marginBottom:5, marginTop:5, marginRight:5}}
                      source={{uri: a}}
              />

            <View >
                <Text style={{fontSize:18, fontStyle:'normal', fontWeight:'bold', color:'#2c3e50', marginBottom:5}}>
                {this.getCategoryTitle(item.status)}
                </Text>

                <Text style={{fontSize:18, color:'#7f8c8d', marginBottom:5, width:250}}>
                  {item.title}
                </Text>
            </View>

        </View>


        </View>


      </TouchableOpacity>

      </Swipeout>

    )
  }
在下一个屏幕(updateNodes)中传递这些值之后,我在componentDidMount函数中使用了以下代码,如下所示-

  this.setState({
    noteId:(
     this.props.navigation.state.params.NOTE_ID
     ? this.props.navigation.state.params.NOTE_ID
     : 'No Value Passed'
    )
  })
当我在第二个屏幕中打印此注释ID值时,它始终显示默认值:未传递值。当我在编辑按键的第一个屏幕上传递其他值时,它不应该是默认值。因此,我不知道在按下开关按钮时传递值是否有错误


如果有人能帮你找出问题所在并解决它,那就太好了。

试试这个。希望对你有帮助


非常感谢,它很有效。但您能解释一下为什么这样的声明-{NOTE_ID:item.ID}是必要的吗?我们必须在导航中作为对象传递数据。
  this.setState({
    noteId:(
     this.props.navigation.state.params.NOTE_ID
     ? this.props.navigation.state.params.NOTE_ID
     : 'No Value Passed'
    )
  })
onPress: () => this.props.navigation.navigate('UpdateNotes',
          NOTE_ID = item.id,
          )
onPress: () => this.props.navigation.navigate('UpdateNotes',{NOTE_ID : item.id}
      )