【发布时间】:2016-05-10 17:07:13
【问题描述】:
我已经尝试了我所知道的所有可能的解决方案。我已经尝试了其他几种类似问题的解决方案,但我不明白这应该如何工作。我正在尝试从 ListView renderRow 方法中调用一个函数。我现在可以调用该函数,但我无法传入我需要的选定 rowData。这就是我得到的:
我需要选中的 rowData。这是代码
constructor(props) {
super(props);
this.onSubmitTrip = this.onSubmitTrip.bind(this);
this.onSelectTrip = this.onSelectTrip.bind(this);
this.renderRow = this.renderRow.bind(this);
this.state = {
dataSource: ds,
showSubmitTripBtn: false
}
}
onSelectTrip(rowData) {
selectedTrip = rowData;
}
renderRow(rowData) {
return (
<TouchableHighlight onPress={this.onSelectTrip} underlayColor='#dddddd'>
<View style={styles.row}>
<View style={{ paddingLeft: 5 }}>
<View>
<Text style={{ fontWeight: "bold", fontSize: 24 }}>{rowData.tripName}</Text>
</View>
</View>
</View>
</TouchableHighlight>
)
}
【问题讨论】:
-
“我现在可以调用该函数,但我无法传入我需要的选定 rowData。” 我看不到您在哪里调用该方法。传递数据就像
this.renderRow(theData)一样简单。
标签: reactjs react-native ecmascript-6