4
當我在地圖循環中放入onPress
時,它不起作用。如何解決它?React Native loop這個
var PageOne = React.createClass({
_handlePress() {
this.props.navigator.push({id: 2,});
},
render() {
return (
<View>
<TouchableOpacity onPress={this._handlePress}> //work here
<Text> One </Text>
</TouchableOpacity>
<View style={styles.albums}>
{
list.map(function(item, index){
return (
<TouchableOpacity key={index} onPress={this._handlePress}> //doesn't work hehre
<Text>{item}</Text>
</TouchableOpacity>
)
})
}
</View>
</View>
);
}
});
感謝您的答案,但得到'未定義一個錯誤」不是一個對象(評估‘_this._handlePress’)':( – Cattla
更新了答案,這應該爲你工作! –
它的工作原理,謝謝! – Cattla