首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >css为json数据添加两行字符

css为json数据添加两行字符
EN

Stack Overflow用户
提问于 2016-03-22 03:43:02
回答 1查看 49关注 0票数 0

我有一个带有行字符的json数据,但是当我在html上呈现该字符时,它确实添加了带有style="white-space: pre-line"属性的新行字符,相反,我想添加2新行字符

我的json数据

代码语言:javascript
复制
[{"id":1,"title":"Israel’s desert city of Beersheba is turning into a cybertech oasis","description":"morphing into a tech oasis.\r\nThe military’s massive relocation of its prestigious technology units.\r\nBeersheba has all of the ingredients of a vibrant security technology ecosystem, \r\n“All in all, projections are that 20,000-30,000 \r\nThe commercial sector has teamed up  cyber attacks.","pub_date":"2016-03-20T10:48:19.394643Z"},{"id":2,"title":"These are testing times: mavericks vs. ice people","description":"One of my earliest engineering jobs, before I fled hardware in favor of the (relative). \r\nThe practice of engineering soon teaches one that, .\r\nSo what do we do? We practice defense in depth. We follow the robustness principle. We “always code as \r\n…Yeah, well, that’s the idea. For my day job at HappyFunCorp I do a lot of interviews, and almost every junior develope.\r\nI don’t necessarily blame them. You can make  go.","pub_date":"2016-03-20T10:50:07.965930Z"}]

更清楚的是,json中的描述如下

代码语言:javascript
复制
morphing into a tech oasis.\r\nThe military’s massive relocation of its prestigious technology units.\r\nBeersheba has all of the ingredients of a vibrant security technology ecosystem, \r\n“All in all, projections are that 20,000-30,000 \r\nThe commercial sector has teamed up  cyber attacks.

正如我们所看到的\r\n,这里我想再次插入新行,以呈现2新行字符

我的控制器

代码语言:javascript
复制
<div class="blog-post">
 <p class="blog-post-title">{{ post.title }}</p>
 <p class="blog-post-meta"><i class="fa fa-clock-o">&nbsp {{ post.pub_date|date  }}</i> </p>
 <span style="white-space: pre-line">{{ post.description }}</span>

如何使用{{ post.description }}的两个新行字符呈现输出?

我期望的输出是这样的

代码语言:javascript
复制
morphing into a tech oasis.

The military’s massive relocation of its prestigious technology units.

Beersheba has all of the ingredients of a vibrant security technology ecosystem, 

“All in all, projections are that 20,000-30,000 

The commercial sector has teamed up  cyber attacks.

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2016-03-22 04:56:25

通过regex从Controller中删除JSON中的所有/r /n:

代码语言:javascript
复制
 post.description.replace(/(?:\\[rn]|[\r\n]+)+/g, "")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36145735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档