如何理解 =!{JSON.stringify(data)} 语法
How to understand =!{JSON.stringify(data)} syntax
谁能帮我看看 JavaScript 中的这段代码是干什么的?
实际上,我正在以 Json 形式从 express 服务器获取数据,当我呈现我的页面时,我想在我的客户端 JavaScript 中访问该数据,这个解决方案是我从 Stack Overflow 中的另一个问题中获得的(Accessing Express.js local variables in client side JavaScript), 但我无法理解这种语法。
var local_data =!{JSON.stringify(data)};
我正在尝试解释这个但无法理解。我使用 handlebars 作为我的模板引擎。
您从代码中获取的问题表明该代码是 Jade template. I searched around for this exact line of code and found it referenced here and here 的一部分,两者都引用了 Jade。
换句话说,这不是有效的JavaScript,但它是有效的翡翠。在这种情况下,!{...}
是 unescaped string interpolation.
的 Jade 语法
Handlebars.js 中的等价物是 {{{...}}}
,所以试试这个:
var local_data = {{{JSON.stringify(data)}}};
谁能帮我看看 JavaScript 中的这段代码是干什么的? 实际上,我正在以 Json 形式从 express 服务器获取数据,当我呈现我的页面时,我想在我的客户端 JavaScript 中访问该数据,这个解决方案是我从 Stack Overflow 中的另一个问题中获得的(Accessing Express.js local variables in client side JavaScript), 但我无法理解这种语法。
var local_data =!{JSON.stringify(data)};
我正在尝试解释这个但无法理解。我使用 handlebars 作为我的模板引擎。
您从代码中获取的问题表明该代码是 Jade template. I searched around for this exact line of code and found it referenced here and here 的一部分,两者都引用了 Jade。
换句话说,这不是有效的JavaScript,但它是有效的翡翠。在这种情况下,!{...}
是 unescaped string interpolation.
Handlebars.js 中的等价物是 {{{...}}}
,所以试试这个:
var local_data = {{{JSON.stringify(data)}}};