简体   繁体   English

将对象从屏幕传递到另一个屏幕| 反应母语

[英]Passing Object from a screen to another one | React-Native

I want to pass my data: Info from the screen WebServiceUse.js to Cellz.js . 我想将数据: Info从屏幕WebServiceUse.js传递到Cellz.js
I don't know how to do it, I can pass one value but not all the data.. 我不知道该怎么做,我可以传递一个值,但不能传递所有数据。
Here's the code: 这是代码:

WebServiceUse.js: WebServiceUse.js:

export default class WebServiceUse extends Component {
    constructor(props) {
        super(props);
        this.state = ({
            Info: [],
            isLoading: true,
            Info1: [],
        })
    }

    componentDidMount() {
        fetch('https://*****', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ id: '1' })
        }).then((response) => response.json()).then((responseJson) => {
            this.setState({
                Info: responseJson.ed5aaf3d933385698d872d0a0d5d4f36,
                isLoading: false,
                Info1: this.Info,
            });
        }).catch((error) => {
            //console.error(error);
            alert(error);
            this.props.navigation.navigate('ScreenTwo');

        });
    }

    render() {
        return (
            <View style={styles.container}>
                {this.state.isLoading &&
                    <View>
                        <ActivityIndicator color="red" size='large' animating={this.state.isLoading} />
                    </View>
                }
                <ScrollView style={styles.welcome}>
                    {
                        this.state.Info.map((item) => {
                            return (
                                <TouchableOpacity onPress={ () => (this.props.navigation.navigate('ScreenSix', {Info: item.id}))}>
                                    <Text>{item.id}</Text>
                                    <Text>{item.date}</Text>
                                    <Text>{item.interlocuteur}</Text>
                                    <View style={styles.Separator} />
                                </TouchableOpacity>
                            )
                        })
                    }
                </ScrollView>
            </View>
        );
    }
}  

Cellz.js: Cellz.js:

export default class Cellz extends Component {

    constructor(props) {
        super(props);}

    render() {
        return (
            <View flexDirection='column' style={styles.container}>
                <View flexDirection='row' style={styles.welcome}>
                    <Text>ID:   </Text>
                    <Text>{this.props.navigation.state.params.Info}</Text>
                </View>
                <View flexDirection='row' style={styles.welcome}>
                    <Text>Ticket ID:    </Text>
                    <Text>{this.props.navigation.state.params.Info}</Text>
                </View>
            </View>

        );
    }
}

What should I do to pass all the Data Info ? 如何传递所有数据Info

You can pass the object if you want to, 您可以根据需要传递对象,

Currently you are doing the following, which only passes the item.id 当前,您正在执行以下操作,仅通过item.id

<TouchableOpacity onPress={ () => (this.props.navigation.navigate('ScreenSix', {Info: item.id}))}>

You can pass the item object if you wanted, or any other object in the following way 您可以根据需要传递item对象,也可以通过以下方式传递任何其他对象

<TouchableOpacity onPress={ () => (this.props.navigation.navigate('ScreenSix', {Info: item.id, item: item}))}>

Then in your Cellz.js 然后在您的Cellz.js

You could get it like this 你可以这样得到

render() {
  const item = this.props.navigation.getParam('item');

  return (
    ...
  );
}

Check out the documentation for more about it. 查看文档以获取更多信息。

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

相关问题 在React-Native中将字符串值从一页传递到另一页 - Passing String value from one page to another page in React-Native React-native传递给另一个组件 - React-native passing component to another 是否可以将参数从一个 react-native 应用程序转移到另一个 react-native 应用程序? - Is it possible to transfer parameter's from one react-native application to another react-native application? 在 react-native 应用程序中渲染另一个屏幕 - Rendering another screen in react-native app React-Native:如果对象未定义,则传递if语句 - React-Native: Passing an if statement if the object is undefined react-native:将完整的STATE从一个组件发送到另一个组件? - react-native: send complete STATE from one component to another? 在 React-native 中从另一个组件更改一个组件的状态 - Changing the state of one component from another component in React-native 在React-Native中将值从一个文件导入到另一个文件 - Issue importing values from one file to another in react-native 如何在本机中将数据从一个屏幕发送到另一个屏幕? - How to send data from one screen to another screen in react native? 如何在React-native中从一个Drawer屏幕切换到非Drawer屏幕? - How to switch from one Drawer screen to a non-Drawer Screen in React-native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM