我如何将换行符添加到json中的事件标题中 [英] How can I add line breaks into my event title in json

查看:151
本文介绍了我如何将换行符添加到json中的事件标题中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一件事我不能直截了当的说就是能够在没有被转义或者实际创建新行的情况下添加html。

这里是我的json:

  {id:30,
title:Basics \\\
Awesome Abs& Butt Blast \ Danielle B ,
开始:2010-05-11T08:00:00-04:00,
结束:2010-05-11T08:30:00-04:00,
allDay:false
}

以下是代码:

  [
<%@ events.each do | e | %GT;
{id:<%= e.id - %> ;,
title:< p><%= e.event_template.level%>< / p> ;< p><%= e.monqi_class.title%>< / p>< p><%= e.instructor.last_initial%>< / p>,
开始:<%= e.start_date.iso8601%>,
end:<%= e.end_date.iso8601%>,
allDay:false
}
<%= @ events.last == e? :,%>
<%end - %>
]

所以我想在里面有3行,(level,class标题和教师)



问题在于它已被转义,所以字符不会被HTML解析



你可以帮我一下吗?



非常感谢



Ami

解决方案

对换行符使用标记,如 | ,然后在输出中用< br /> 替换它。


one thing i can not get straight is the ability to add html without it being escaped or actually creating new lines

here's my json:

{ "id": 30,
  "title": "Basics \n  Awesome Abs & Butt Blast \n  Danielle B",
  "start": "2010-05-11T08:00:00-04:00",
  "end": "2010-05-11T08:30:00-04:00",
  "allDay": false
}

and here's the code for it:

[
  <% @events.each do |e| %>
        { "id": <%= e.id -%>,
        "title": "<p><%= e.event_template.level %></p><p><%= e.monqi_class.title %></p><p><%= e.instructor.last_initial %></p>",
            "start": "<%= e.start_date.iso8601 %>",
            "end": "<%= e.end_date.iso8601 %>",
            "allDay": false
         }
        <%= @events.last == e ? "" : ","  %>
    <% end -%>
]

so I am trying to have inside an even 3 lines, (level, class title, and instructor)

the problem is it's getting escaped so the charcters are not being parsed by html

can you please help me with that?

Thanks a lot

Ami

解决方案

Use a token for a line-break, like ~ or |, then replace it with <br /> on the output.

这篇关于我如何将换行符添加到json中的事件标题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆