【发布时间】:2019-09-15 17:30:35
【问题描述】:
我正在设置一个应用程序,在 GUI 端,我想以不同的行而不是单行显示文本注释。
目前它的工作原理如下:
1. 从后端接收 json 文件,其中包含 key:value 对进行注释。
示例->
评论:“服务的应用程序实体标题。
发送系统必须使用完全相同的名称向服务发送数据。
- 在 GUI 端,在解析 JSON 文件后,GUI 尝试显示注释。
问题:GUI 无法识别 HTML 标记
并且不显示换行符。
问题:我是否需要在后端(在 C# 中)以不同的方式处理它?
从后端收到的json:
Comment: "Application Entity Title for Service.<br/> The sending system must use exactly the same name to send data to service. <br/>"
GUI反应代码
<div className="Setting__Comment">
<p>
<strong>Description: </strong>
{node.Comment}
</p>
</div>
GUI 端的当前结果
Description: Application Entity Title for Service.<br/> The sending system must use exactly the same name to send data to service. <br/>
预期结果。
Description: Application Entity Title for Service.
The sending system must use exactly the same name to send data to
service.
对我有用的解决方案:
displayComment(){
var node = this.props.treeNode;
return {__html: node.Comment};
<div className="SettingsTreeValueNode__Comment">
<p>
<strong>Description: </strong>
<div dangerouslySetInnerHTML={this.displayComment()}/>
</p>
</div>
</div>
【问题讨论】:
-
从你得到这个
<br/>的地方意味着它是来自node.Comment还是来自其他地方? -
是的,我从 node.Comment 得到它。需要明确的是,getrequest 从客户端发送到服务器,作为服务器的响应,客户端获取 json 对象。客户端通过这个json对象,得到“评论”的信息。
-
那么你需要设置
dangerouslySetInnerHTML属性。请点击此链接reactjs.org/docs/dom-elements.html -
谢谢大家。
-
描述:
displayComment(){ var node = this.props.treeNode;返回 {__html: node.Comment};