how to make React Native ListView When click on row make the row different
2016-08-09 06:51
786 查看
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
相关文章推荐
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- [Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?
- How to Capture the Row Selected on Search Page In a Variable?
- Notes on how to use Webots, especially how to make a robot fly in the air
- how to fix the problem when you install matlab on *nix-- "libXp.so.6 : cannot open "
- how to fix the problem when you install matlab on *nix-- "libXp.so.6 : cannot open "
- [Selenium]How to click on a hidden link ,move to the drop down menu and click submenu
- Winform: how to cancel the winform close when click the "x" button
- How To Add Simple "Install WebPart" Menu to the Right Click On a CAB File
- [English Homwork] How to make money on the Internet
- How To Install Discuz 3.2 on the One-Click LEMP Application
- How to allow a user to click on TextBlocks which return an integer ID in the click handler
- How to pass the value to the function when clicking on the UIButton
- [旧稿]How To Add Simple "Install WebPart" Menu to the Right Click On a CAB File
- How to display an empty row when the underlying dataset is empty
- How to make app start automatically When the application starts
- *****How to handle a double-click on a grid row or cell
- [English Homwork] How to make money on the Internet
- use noscript html tag when user disable the javascript in browser, guide user how to enable the js in different browser and retu
- How to grant access to SQL logins on a standby database when the guest user is disabled in SQL Serve