how to make React Native ListView When click on row make the row different
来源:互联网 发布:挖财怎么用淘宝号登陆 编辑:程序博客网 时间:2024/05/17 23:35
how to make React Native ListView When click on row make the row different
example code
import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, ListView, TouchableWithoutFeedback} from 'react-native';const peopleArray=[{id:'1',name:'lilei'},{id:'2',name:'zhangsan'}]class demo extends Component { constructor(){ super(); const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}); this.state={ data:peopleArray, DS:ds.cloneWithRows([]) } } componentDidMount(){ this.setState({DS:this.state.DS.cloneWithRows(this.state.data)}); } renderRow=(item)=>{ return ( <TouchableWithoutFeedback onPress={()=>this.handlePress(item)}> <View style={styles.item}> {item.onPressed? <Text>click</Text> :<Text>{item.name}</Text> } </View> </TouchableWithoutFeedback> ); } handlePress(itemData){ const dataClone=peopleArray; for (var i = 0; i < dataClone.length; i++) { dataClone[i].onPressed=false; if(dataClone[i]==itemData){ dataClone[i].onPressed=true; } } this.setState({ data:dataClone }); } render() { return ( <View style={styles.container}> <ListView dataSource={this.state.DS} renderRow={this.renderRow} /> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', backgroundColor: '#F5FCFF', }, item:{ height:40, borderBottomWidth:1, justifyContent:'center', alignItems:'center' }});AppRegistry.registerComponent('demo', () => demo);
relate
http://stackoverflow.com/questions/33663461/react-native-listview-row-not-re-rendering-after-state-change
last update 2016-08-10
0 0
- how to make React Native ListView When click on row make the row different
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- How to make two <div>…</div> in the same row?
- AxWindowsMediaPlayer how to make the Tracker disappear when playing
- [English Homwork] How to make money on the Internet
- how to make the XVim still available on xcode7
- How to display an empty row when the underlying dataset is empty
- how to make native activity to apk
- How to Capture the Row Selected on Search Page In a Variable?
- how to make run command include the provided dependencies when using sbt
- How to make the sprite image ?
- How to make the strings upside down
- How to save the currently edited row without moving to another row
- How to make XAML project to build faster on the Windows Platform
- The row value(s) updated or deleted either do not make the row unique or they alter multiple rows.
- How to make XStream skip unmapped tags when parsing XML?
- How to make UITextField move up when keyboard is present
- How to select the full row in DataGrid
- python map, reduce, filter 函数
- 来自于PayPal的RESTful API标准
- 【学习Linux】输入输出的重定向,管道
- hdu-1715大菲波数(数组表示大数)
- IBM Bluemix Local new parts deliver additional units of capacity
- how to make React Native ListView When click on row make the row different
- thinkphp 3.2里面session的redis驱动文件(可分布式)
- 上班第一天
- thinkphp 3.2中独立的redis快捷函数 模仿 S() 函数
- Blender 安装
- geoserver服务wfs之GetFeature
- 一个完美的PHP ZIP压缩类代码
- PAT乙级:1007. 素数对猜想 (Java)
- c语言版本双人贪吃蛇