0
var Restaurant = React.createClass({
resPress: function (resId, resName) {
this.props.navigator.push({
name: 'viewMenu',
id: resId,
placeName: resName
});
},
render: function() {
var that = this;
return (
<View>
{this.state.place.map((item, i) => (<TouchableOpacity key={i} onPress={() => this.resPress(item.res_id, item.res_name)} ><Text>{item.res_name}</Text></TouchableOpacity>))}
</View>
)
}
});
這很好。我的問題是爲什麼我不能像下面提到的那樣將值傳遞給'resPress'?通過在React Native中觸發onPress將值傳遞給方法
onPress={this.resPress(item.delivery_id, item.place_name)}
你不需要'bind'該功能,如果你已經在使用胖箭頭了。你可以簡單地做:'onPress = {(yourData)=> this.resPress(yourData)}'。 –
是啊,我對Apologize.tnx發表評論。 –