循环一个文章列表
实现一个循环列表
第一步代码如下
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
class Email extends Component {
render(){
return(
<View style={styles.container}>
<Text style={styles.text}>{this.props.name}</Text>
<Text style={styles.text}>{this.props.url}</Text>
</View>
)
}
}
export default class App extends Component{
render(){
return(
<Email name="框架研发部" url="www.baidu.com"/>
)
}
}
var styles=StyleSheet.create({
container:{
flex:1,
paddingTop:40,
},
text:{
color:'red'
}
})
效果如下
第二步加入数据层
代码为:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,ScrollView} from 'react-native';
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
class Email extends React.Component {
render(){
return(
<View style={styles.container}>
<Text style={styles.text,styles.title}>{this.props.title}</Text>
<Text style={styles.text}>{this.props.author}</Text>
<Text style={styles.text}>{this.props.time}</Text>
</View>
)
}
}
export default class App extends React.Component{
render(){
var articles = [
{
title: "React-Native入门指南",
author: "vczero",
time: "2015-06-28"
},
{
title: "为什么世界不一样",
author: "vczero",
time: "2015-06-8"
},
{
title: "你来,我就告诉你",
author: "vczero",
time: "2015-04-01"
}
];
return(
<ScrollView>
{
articles.map(function(article){
return <Email title={article.title} author={article.author} time={article.time}/>
})
}
</ScrollView>
)
}
}
var styles=StyleSheet.create({
container:{
flex:1,
paddingTop:20,
flexDirection:'row'
},
text:{
color:'red'
},
title:{
color:'blue'
}
})
效果如下
作者:jser_dimple
-------------------------------------------
个性签名:一个人在年轻的时候浪费自己的才华与天赋是一件非常可惜的事情
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!
微信
支付宝