Reactjs转换为HTML [英] Reactjs convert to html
问题描述
我在处理Facebook的ReactJS麻烦。每当我做Ajax和要显示一个HTML数据,ReactJS将其显示为文本。 (见下图)
I'm having trouble dealing with facebook's ReactJS. Whenever I do ajax and want to display an html data, ReactJS displays it as text. (See figure below)
该数据是通过了jQuery的成功回调函数显示阿贾克斯。
The data is displayed through the success callback function of the jquery Ajax.
$.ajax({
url: url here,
dataType: "json",
success: function(data) {
this.setState({
action: data.action
})
}.bind(this)
});
有没有简单的方法将其转换成HTML?我应该怎么办呢用ReactJS?
Is there any easy way to convert this into html? How should I do it using ReactJS?
推荐答案
在默认情况下,作出反应脱HTML到prevent XSS。如果你真的想渲染HTML,您可以使用 dangerouslySetInnerHTML
属性:
By default, React escapes the HTML to prevent XSS. If you really want to render HTML, you can use the dangerouslySetInnerHTML
property:
<td dangerouslySetInnerHTML={{__html: this.state.actions}} />
阵营势力这一有意-繁琐的语法,这样你就不会意外文本呈现为HTML和引入XSS漏洞。
React forces this intentionally-cumbersome syntax so that you don't accidentally render text as HTML and introduce XSS bugs.
这篇关于Reactjs转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!