在列表视图中,当单击 renderRow 中显示刻度线的列表视图数据时,我这样写
constructor(props){
super(props);
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state={
dataSource: ds.cloneWithRows(['row 1', 'row 2'])
}
}
componentDidMount(){
//After getting data from service i am setting data to the dataSource
this.setState({ dataSource: ds.cloneWithRows(responseData.data.listTeamBySportId) })
}
onTeam(rowData,rowID){
if(this.state.opacity == rowID){
this.setState({opacity:null})
}else{
this.setState({opacity:rowID})
}
}
render(){
<ListView
style={{flex:1}}
dataSource={this.state.dataSource}
renderRow={this.renderData.bind(this)}
renderSeparator={(sectionID, rowID) => <View key= {`${sectionID}-${rowID}`} style={styles.separator} />}
automaticallyAdjustContentInsets={false}/>
}
renderData(rowData,sectionID:number,rowID:number){
return (
<View style={styles.subBody}>
<TouchableHighlight onPress={this.onTeam.bind(this,rowData,rowID)}>
<View style={{backgroundColor:rowData.colorCode,height:44,flexDirection:'row'}}>
<View style={styles.centersubBody}>
<Text style={{color:'white',fontWeight:'bold',fontSize:17,fontFamily:'Roboto-Medium',marginLeft:10}}>{rowData.location}</Text>
</View>
<View style={styles.rightsubBody}>
{this.state.opacity == parseInt(rowID) ? (
<Image style={{marginRight:5,marginTop:5, width:25, height:25, marginBottom:10}} source={require('image!selected')}/>
):<View></View>}
</View>
</View>
</TouchableHighlight>
</View>
);
}
我的 react-native 版本是:0.51.0 这里的问题是当数据最多 10 条记录时,我的代码在 OnTeam 函数中的 setState 之后工作,它再次渲染到 renderRow() 并显示刻度线,但问题是数据何时超过 10 条记录它不会进入 renderRow 数据,请给我建议如何解决它任何帮助非常感谢