react-native的ListView控件的使用
来源:互联网 发布:springmvc json 编辑:程序博客网 时间:2024/05/17 23:45
react-native的ListView控件的使用
1.数据准备
// 在构造方法中准备 constructor(props) { super(props); this.state = { // 创建一个DataSource dataSource: new ListView.DataSource({ rowHasChanged: ((row1, row2) => row1 !== row2) }), // 是否加载完毕 load: false } }
2.创建ListView
render() { return ( <View> <ListView dataSource={this.state.dataSource} {/*这里是每个item的布局,这里在方法中实现*/} renderRow={this.getItemView} /> </View> ); } getItemView(item) { return ( <View> <Text style={styles.itemHeader}>{item.desc}</Text> <View style={styles.item}> <Text style={styles.itemMeta}>{item.who}</Text> <Text style={styles.itemMeta}>{item.createdAt}</Text> </View> </View> ); }
3.在componentDidMount生命周期中执行数据请求
// 发起数据请求 componentDidMount() { this.getMoviesFromApiAsync(); } // 使用自带的网络请求请求数据 getMoviesFromApiAsync() { fetch('http://gank.io/api/data/Android/10/1') .then((response) => response.json()) .then((responseJson) => { this.setState({ //改变加载ListView load: true, //设置数据源刷新界面 dataSource: this.state.dataSource.cloneWithRows(responseJson.results), }) }) .catch((error) => { console.error(error); }); }
阅读全文
0 0
- react-native的ListView控件的使用
- React Native中ListView的简单使用
- React-native 之Text控件的使用
- React Native 基本控件的使用
- React Native的组件ListView
- react-native listview使用
- React Native 学习笔记十(ListView的使用)
- React Native从零开始(六)ListView的简单使用
- React Native控件之Listview
- React Native控件之Listview
- React Native控件之ListView
- react native 实现ListView的局部更新
- React Native -- ListView的基本用法
- React Native ListView的滚动scrollTo
- react-native ListView的简单用法
- React-Native ListView简单使用
- 【React Native开发】- React Navigation的使用
- 解决React Native中ListView控件在ios上不能滑动的问题
- 20171025心情总结
- 冒泡排序
- Druid连接池 报错:abandon connection原因分析
- NIO 学习(六) ServerSocketChannel
- 分值算法
- react-native的ListView控件的使用
- Linux下Tomcat6配置HTTPS单向认证
- maven目录结构
- CentOS的free命令
- python 之模拟登陆csdn
- 用友数据库源配置
- 系统虚拟机安装与管理
- angular上传图片,最近自己研究了一个。笨方法。
- Hadoop常见报错解答