Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Internet Explorer中的String.raw等效项?_Javascript_Python_String_Internet Explorer_Templates - Fatal编程技术网

Javascript Internet Explorer中的String.raw等效项?

Javascript Internet Explorer中的String.raw等效项?,javascript,python,string,internet-explorer,templates,Javascript,Python,String,Internet Explorer,Templates,我返回一个使用Python的Zope生成的DTML模板,并通过在浏览器中对其求值为其分配一个JS变量。我的模板如下所示: var html = <dtml-var "html"> # which is nothing but var html = "<html> <body> Hello </body> </html> " 为什么需要String.raw?(看起来不像是这样,似乎需要模板字符串,这在IE中永远不会起作用)。此外,您还

我返回一个使用Python的Zope生成的DTML模板,并通过在浏览器中对其求值为其分配一个JS变量。我的模板如下所示:

var html = <dtml-var "html">

# which is nothing but
var html = "<html>
<body>
Hello
</body>
</html>
"

为什么需要
String.raw
?(看起来不像是这样,似乎需要模板字符串,这在IE中永远不会起作用)。此外,您还可以使用
JSON.stringify()
从常规字符串生成文本。
String.raw
他们说是用于模板的,所以我使用了它,效果很好<代码>JSON.stringify是Javascript格式的,对吗?我的意思是,首先我如何从数据库进入JS?你是要我换一种方式储存吗?我将HTML直接存储到数据库并检索它。这个问题可能有多种解决方案,但我只是在想哪种方法是好的。哦,只要在后端将DB中的字符串转换为JSON,它就会作为一个有效的JS字符串到达客户端,即使DB源字符串中有换行符……所以你的意思是
var html=JSON.parse(jsonified)
我想我需要理解什么是
JSON
更好:)如果您意识到我也在执行它。是的,这应该将字符串解包到一个多行/引号中,并且字符串没有问题。
var html = String.raw`<dtml-var "html">` 
# Replace newline character to \n literally.
html.replace("\n",\\n")

# Escape the double quotes
html.replace("\n",\\n").replace("\"", "\\\"") i.e replace " with \"