【发布时间】:2019-05-14 06:49:25
【问题描述】:
我尝试了不同的方法来渲染 json 响应中的 html 内容以响应本机。但是我在这些方法中失败了
因为没有包支持html 的table 标签。所以我想在原生反应中使用 WebView。但这也让我失望了。 WebView 中的 json 响应中没有提供 html content 的字段。我试过以下。
但是这些都不起作用
代码
<WebView
source={{uri: `<h1>Hello World</h1>`}}
style={{marginTop: 20}}
/>
在我的情况下,我正在获取服务器响应。我已经仔细检查了响应是否到来,来自服务器的响应很好。
return (
<Container style={styles.container}>
<View>
{this.state.section.map(article =>
<View>
<WebView
source={{uri:article.data.description}}
style={{marginTop: 20}}
/>
</View>
)}
</View>
</Container>
);
除了这些之外,还有其他方法可以呈现 html 内容吗?请让我坚持下去。我不知道该怎么办。这会导致我的项目延迟。所以我真的很失望。请任何帮助都会非常感激。
【问题讨论】:
-
请给
WebView添加一些高度和宽度,然后看看它是否出现?我很难知道只有在您为其提供高度和宽度时才会呈现 WebView。此外,react-native-render-html非常好,但它落后了很多地方。尝试根据您的需要对其进行自定义,这真的很容易,人们写得很好。 -
是的,我试过给
<WebView source={{html:article.data.description}} style={{flex: 1, height:200, width:200}} />。但我仍然得到一个空白页。但是react-native-render-html不支持table标签。
标签: reactjs react-native webview jsx html-rendering