admin管理员组文章数量:1200977
I am trying to use this section of code from jQuery UI's tabs example and convert it to Coffeescript. I've run it through the awesome / tool.
var tabTitle = $( "#tab_title" ),
tabContent = $( "#tab_content" ),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
tabCounter = 2;
The problem is that tabTemplate variable declaration. Coffeescript is trying to do string interpolation on it, as far as I can tell. I've tried escaping it with a slash, but that just resolves to using a slash in the converted js.
I am trying to use this section of code from jQuery UI's tabs example and convert it to Coffeescript. I've run it through the awesome http://js2coffee.org/ tool.
var tabTitle = $( "#tab_title" ),
tabContent = $( "#tab_content" ),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
tabCounter = 2;
The problem is that tabTemplate variable declaration. Coffeescript is trying to do string interpolation on it, as far as I can tell. I've tried escaping it with a slash, but that just resolves to using a slash in the converted js.
Share Improve this question edited Dec 22, 2011 at 18:33 Robert Harvey 181k48 gold badges347 silver badges512 bronze badges asked Dec 22, 2011 at 18:31 DanDan 1,2622 gold badges19 silver badges33 bronze badges2 Answers
Reset to default 15Use single-quotes to delimit your string: http://coffeescript.org/#strings
If you want to use single-quotes within your string without manually escaping them you can use 3 single-quotes:
x = '''
my string's ok with single quotes and #{doesn't interpolate}
'''
That said, this is HTML, so double-quotes are actually more common for attributes than single-quotes. Your string could therefore be written as:
tabTemplate = '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>'
without any problems.
Escaping with backslash does work:
$ coffee -bce '"\#{a}"'
"\#{a}";
$ coffee -bce '"#\{a}"'
"#\{a}";
本文标签: javascriptHow to escape string interpolation in CoffeescriptStack Overflow
版权声明:本文标题:javascript - How to escape string interpolation in Coffeescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738580207a2101119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论