html - 如何在不使用 Webview 的情况下在 React Native 中呈现多个 HTML 内容?
问题描述
我正在做反应原生项目。
在那里,我们得到了 Json 数据的问题和答案。对于 Answers,我们在 answers 键中获取 HTML 内容。
所以,我必须在 flatlist 中显示答案的数量。有没有在不使用 Webview 的情况下呈现 HTML 内容?
Json 类似于以下示例:
[ { question: 'How do I change or reset my password?',
answer: <p style="color:#B22222">Color text and <span style="color:limegreen;">another color</span>, and now back to the same. Oh, and here's a <span style="background-color:PaleGreen;">different background color</span> just in case you need it!</p>
},
{ question: 'How do I change my user name?',
answer: <p>Here's a blockquote:</p>
<blockquote>Contents should not be swallowed. This is due to the enormous amount of harmful chemicals that has gone into this burger.</blockquote>
<p>That was a blockquote.</p>
},
{ question: 'How do I change my email ID?',
answer:<p style="font-size:18pt">Text size using points.</p><p style="font-size:18px">Text size using pixels.</p><p style="font-size:larger">Text size using relative sizes.</p>
},
....
]
数据是动态的,并且有不同的答案和问题。
任何建议,在不使用 Webview 的情况下,我们可以将 HTML 内容渲染到 flatlist for loop 中吗?
解决方案
...
import HTML from 'react-native-render-html';
...
<HTML tagsStyles={{
p: styles.textAuthor}}
html={htmldata}
imagesMaxWidth={screen.screenWidth}
/>
使用这个库,您可以在渲染之前操作 HTML 节点。
推荐阅读
- java - 使用 Java 重新连接到进程
- static-libraries - Mingw64:添加静态链接库添加 libstdc++ 依赖项
- python - 如何最好地存储和调用在单个 XLSX 文件上运行的 pandas 脚本?
- python - python中属性装饰器对可变属性的用处
- node.js - 如何使用 Jest 库测试基本的 socket.io Node.js 应用程序?
- discord.js - 不和谐机器人有可能进入国外服务器吗?
- javascript - 为什么 React Context 只会触发从 DOM 元素向下传递的值函数
- apache-kafka - 用于实时交易平台的 kafka 每分钟处理数百万美元的交易?
- python - 如何在 if else 语句之后继续你的代码而不中断?
- symfony - 由 make:registration-form 制作的表单中的 Symfony 4.3 错误