简体   繁体   English

如何使用JS正确渲染包含换行符的内容?

[英]How can properly render content that contain new line using JS?

I have a string look like this that I query from the database. 我有一个这样的字符串,我从数据库中查询。

In the controller, I ran 在控制器中,我跑了

dd($disclaimer);

I get 我懂了

"""
q\n
a
"""

Then, I'm trying to access it the JS like this 然后,我正在尝试像这样访问它

$scope.disclaimer.text = '{!! $disclaimer or '' !!}';

I also try 我也尝试

$scope.disclaimer.text = JSON.parse('{!! $disclaimer or '' !!}');

I kept getting 我不断

Uncaught SyntaxError: Invalid or unexpected token 未捕获的SyntaxError:无效或意外的令牌

How would one go about debugging this? 如何调试这一点?

以防万一有人遇到相同问题,这对我来说似乎是个窍门。

$scope.disclaimer.text = JSON.parse(JSON.stringify({!! json_encode($disclaimer) !!}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM