React Native 截取后端数据返回Html标签中的值
来源:互联网 发布:matlab读取mat数据 编辑:程序博客网 时间:2024/06/05 09:59
import React, { Component } from 'react';import { StyleSheet, View, Dimensions, Text} from 'react-native';import { Widget } from 'rn-yunxi';const { width, height } = Dimensions.get('window');//模块声名并导出export default class EmText extends Component { //默认属性 static defaultProps = { str: '<em>红酒</em>', }; //构造函数 constructor(props) { super(props); let normalText = []; let specialText = []; if (props.str && props.str !== '' && props.str.length > 0) { try { let tempText = props.str; tempText = tempText.replace(/<[^>]*>/g, 'tmd') tempText.trim().split('tmd').forEach((obj, index) => { if ((index + 1) % 2 === 0) { normalText.push(obj) } else { specialText.push(obj) } }) } catch (e) { } } this.state = { //状态机变量声明 normalText, specialText, } } //渲染 render() { const { normalText, specialText, } = this.state if (normalText && normalText.length > 0) { return ( <Text > {normalText.map((obj, i) => { return (<Text>{obj} <Text style={{ color: 'red' }}>{specialText[i]}</Text> </Text>) })} </Text> ); } return ( <Text >{this.props.str}</Text> ); }};
使用方法:
<EmText str={'<a>获取后端数据返回Html标签中的值</a>'} />
取到的值就是: 获取后端数据返回Html标签中的值
阅读全文
0 0
- React Native 截取后端数据返回Html标签中的值
- react-native tab标签
- react-native缓存数据
- 猫猫学iOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- AJ学IOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- React-Native中的布局
- React Native中的事件
- React-Native 中的ListView
- React-Native 中的生命周期
- React-Native中的Text
- DEDEcms过滤内容中的html标签, 并且截取字符串
- react-native 类标签传递值给类
- 去掉服务端返回html数据中的 
- React Native 中 网络访问 返回数据加载的问题Util
- react-native react 中的bind(this)
- react-native Android返回键以及 webview 中的回退处理
- React Native中的flexbox布局
- react native中的layoutAnimation组件
- Qt5.5.1 cmake 编译配置opencv3.2
- Redis的安装使用入门
- SAP Leonardo IoT 产品组合
- Item 1:视C++为一个语言联邦【effective C++读书笔记】
- ASP.NET
- React Native 截取后端数据返回Html标签中的值
- linux日志服务(2):syslog日志整体框架原理
- 没有网络跳转到设置网络页面
- 关于 Java 数组的 12 个最佳方法
- EJB使用到的一些名词说明
- Unity3D中Rigidbody.velocity和Addforce的区别
- Golang 实现简单的定时器
- 643. Maximum Average Subarray I
- 07 Servlet ServletConfig对象 ServletContext对象共享数据和读取数据