[英]Templating and escaping with Coffeescript/JQuery
This below selector in some coffeescript that I wrote keeps giving me trouble. 我写的一些咖啡文字下面的选择器总是给我带来麻烦。
$('span[data-id="#{cat_id}"]').attr('class', 'dropdown-toggle icon-button fold')
When compiled and run, the text inside the quotes becomes: 编译并运行后,引号内的文本变为:
span[data-id="#{cat_id}"]
I tried changing the single quotes on the outside of the selector to double quotes, but then I get a runtime error: 我尝试将选择器外部的单引号更改为双引号,但随后出现运行时错误:
ExecJS::RuntimeError in Application#handle_404 Showing /Users/michaeldiscenza/Documents/RUN_source_repos/run_portal/app/views/layouts/application.html.erb where line #33 raised: [stdin]:222:88: error: unmatched OUTDENT $('span[data-id="#{cat_id}"]').children().attr('class', 'icon toggle collapse') ExecJS :: RuntimeError在Application#handle_404中显示/Users/michaeldiscenza/Documents/RUN_source_repos/run_portal/app/views/layouts/application.html.erb,其中第33行出现:[stdin]:222:88:错误:不匹配的OUTDENT $ ('span [data-id =“#{cat_id}”]')。children()。attr('class','icon toggle crash'')
I've tried concatenating "/'" + selector + "/'"
, but that didn't work either. 我尝试串联
"/'" + selector + "/'"
,但这也不起作用。
$("span[data-id=#{cat_id}]")
我猜想在内部的引号是不必要的,但是在外部仍然需要用双引号来解释#{}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.