我在表述该标题时遇到了一些麻烦,但我的问题是,当我解析为 html 时,JSON 字典中字符串中的 \n 字符被无效。
var exp = {
"globalRunInfo" : {
"file" : "file/path/goes/here",
"info" : "random junk here",
"copyright" : "this is where I am getting my problem \n the newline doesn't work \n so all this gets formatted as one line"
}
}
ko.applyBindings(exp);Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div data-bind="with: globalRunInfo">
<p data-bind="text: file"></p>
<p>SOMETHING</p>
<p data-bind="text: info"></p>
<span data-bind="text: copyright"></span>
</div>
</html>Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?我试图避免编写一个检查换行符并用换行符或其他内容替换它们的函数。对于我将要使用一次的东西来说,这是一项繁重的工作。