我有一个表单,用户可以选择三个成员选项之一。我正确渲染了屏幕,但按钮切换不起作用。当我单击其他按钮时,勾号仍停留在第一个选项上。这是我的代码
<View style={styles.mainview}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) =>
<TouchableHighlight onPress={() => this.toggleOneYear(rowData.id, rowData.i)} style={styles.registerButton} underlayColor='#ffffff'>
<View style={styles.detailBoxTick}>
{renderIf(rowData.i == 1)(
<Image style={styles.imageTickStyle} source={this.state.payoneyear ? Images.rememberTickImg : Images.rememberUnTickImg} />
)}
{renderIf(rowData.i == 2)(
<Image style={styles.imageTickStyle} source={this.state.paytwoyear ? Images.rememberTickImg : Images.rememberUnTickImg} />
)}
{renderIf(rowData.i == 3)(
<Image style={styles.imageTickStyle} source={this.state.paythreeyear ? Images.rememberTickImg : Images.rememberUnTickImg} />
)}
<Text style={styles.tickBoxText}>
{rowData.card_duration} years Membership ${rowData.price}
</Text>
</View>
</TouchableHighlight>
}
enableEmptySections
/>
</View>
toggleOneYear(id, counter) {
if (counter == 1) {
console.log('counter ', counter)
console.log('payoneyear ', this.state.payoneyear)
this.setState(
{
payoneyear: true,
paytwoyear: false,
paythreeyear: false
}
)
console.log('payoneyear ', this.state.payoneyear)
}
else if (counter == 2) {
console.log('counter ', counter)
console.log('payoneyear ', this.state.paytwoyear)
this.setState(
{
payoneyear: false,
paytwoyear: true,
paythreeyear: false
}
)
console.log('paytwoyear ', this.state.paytwoyear)
}
else if (counter == 3) {
console.log('counter ', counter)
this.setState(
{
payoneyear: false,
paytwoyear: false,
paythreeyear: true
}
)
}
}
我在上面的代码中做错了什么?有人可以帮忙吗?提前致谢