React Native JSON解析和辅助函数(2)
appBody.js
这里 super 和 componentDidMount 是React内置函数。 使用 super, 您可以初始化 此 值,并且 componentDidMount 首先是调用。 从 ‘ react ‘ 导入 React,{Component} ; 从 ‘ react-native ‘ 导入 { Text } ; 从 ‘ native-base ‘ 导入 {Content,Card,CardItem,Body} ; 从 ‘ ./appBodyData ‘ 导入 AppBodyData ; export 默认 类 AppBody 扩展了 Component { constructor (){ super () this。 state = { data:[] } } getData (){ return fetch (‘ https://www.thewallscript.com/blogfeed/javascript/10 ‘) 。 然后 ((response)=> response.json()) 。 然后 ((responseJson)=> { 此。 的setState ({数据:responseJson.feed.entry}); }) 。 捕捉 ((误差)=> { 控制台。 错误 (误差); }); } componentDidMount (){ this。 getData (); } render(){ return ( < AppBodyData data = {this。 state .data} /> ); } } 模块 .EXPORT = AppBody ; appBodyData.js <Body> < Text > { articleData .title。$ t } </ Text > </ Body> </ CardItem> </ Card> ) }); return( <Content> { articles } </ Content> ); } } 安装React包 Time Ago HTMLView将 适合图像 帮助程序功能 在 src 文件夹 下创建文件目录 。 helpers.js 导出 函数 GetImage (content){ 导出 功能 ContentSnippet (内容){ 视频教程 - React Native Helper / Injectable Functions appBodyData.js export default class AppBodyData extends Component { render(){ let articles = this。 道具 .data。 map ( function ( articleData ,index){ return( <Card> <CardItem> <Left> <Thumbnail source = {require(‘../ img / SrinivasTamada.png‘)} /> < HTMLView value = { ContentSnippet( articleData .content。$ t)} /> 返回( < 文章 } </ Content> ); } } 模块 .EXPORT = AppBodyData ; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |