簡體   English   中英

React native,讓我知道this.props.navigation.state

[英]React native, let me know the this.props.navigation.state

我正在嘗試從A.class檢索數據到B.claa。 當我直接在A類中返回一個按鈕時,可以將A中的數據檢索到B類中以進行顯示。

但是,當我使用for循環創建用於創建按鈕的函數時,實際上並不會檢索數據。 它只是未定義..

在這里,有A類和B類。因此,基本上,在A類中,有5個按鈕鏈接到B類的屏幕B屏幕應該從A中獲取數據以顯示在其屏幕中。

請讓我知道此解決方案。

A級

const renderButtons = (navigateG) => {
const views = [];
const Name= ["AB","BC","cd","ef","gg"]
for ( var i =0; i<5; i++){
views.push(
<Button
   key={i}
   onPress={() => navigateG('B', { 
                    Title:"hi",
                    Name:Name[i],

                })}
   title="Learn More"
   color="#841584"
   accessibilityLabel="Learn more about this purple button"
/>);
} // % buttons are created. 

return views;
}
export default class A extends Component {

 static navigationOptions = ({ navigation }) => ({
    title: 'A',
    headerLeft: <MenuButton navigation={navigation}/>
});

render() {  
  const { navigate } = this.props.navigation;    
    return ( 
     renderButtons(navigate) )
 }
     </ScrollView>

    );
 }
}

B級

export default class B extends Component {
static navigationOptions = ({ navigation }) => ({
    title: `${navigation.state.params.Title}`
});
render(){return(   <Text>{ this.props.navigation.state.params.Name }</Text> )}

您可以使用this.props.navigation.state.params.Name而非this.props.navigation.state.Name訪問導航狀態的名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM