請原諒我,如果這是簡單的我忽略。我對編程相當陌生,對React和React Native更新。如何在Actions.SCENE_KEY中使用變量(反應本地路由器通量)
我正在構建一個簡單的導航抽屜。
抽屜顯示一個Menu組件,該組件具有返回以下內容的renderMenuItem(item)
函數。
<Button onPress={() => this._onItemSelect(item)} style={styles.navItem} >{item}</Button>
它負責將正確標記的按鈕返回到渲染功能。
我遇到的問題是,當它到達onItemSelect
funtion,
_onItemSelect(item) {
// handle action to render the new page!
Actions.item // Won't work
//Actions.Page2 // Hardcoding the scene here won't work either
);
我不能按下按鈕時,實際顯示的新景象。如果我要將場景硬編碼到按鈕中的onPress()
函數中,我可以使其工作。例如:
<Button onPress={Actions.Page2} style={styles.navItem} >{item}</Button>
很明顯,這是行不通的。我需要的是能夠在功能renderMenuItem(item)
函數或onItemSelect(item)
函數中使用項目。
謝謝。自從昨晚試圖找出這個問題以來,我一直在破壞我的大腦。
儘管這並沒有完全解決我的擔憂,但確實讓我走上了正確的道路。我想要的是一種使用item(其中包含按下按鈕的名稱)作爲動作的方式。 (例如:'Actions.item()')這沒有用。不過,我只是在_onItemSelect函數中使用了一個switch語句。 (item){ case「page one」: Actions.PageOne(); 休息; 案例「第二頁」: 操作。PageTwo(); 休息; }' 非常感謝您的幫助。 – StevenAntonio