将主干响应嵌入 Rails 中的下划线模板中?
我正在将backbone.js 用于我正在进行的一个rails 项目。我使用类似以下内容将模板嵌入到 Rails 视图中:
<script type="text/template" id="this-is-the-id">
... template goes here ...
... the line below this is where my error's coming from ...
<%% _(<%= aNumber %>.times(function(){ console.log('hi'); });) %>
</script>
我收到错误 Uncaught SyntaxError: Unexpected token <
。如果我用整数替换 <%= aNumber %>
,它会按预期工作。另外,如果我 console.log(<%%= aNumber %>)
,它会记录正确的数字。
有谁知道我怎样才能完成这样的事情?我知道这是一种组织代码的草率方式,但这只是我正在组合的一个快速小技巧。
谢谢!
I'm using backbone.js for a rails project I've got on the side. I'm embedding templates in the rails views using something like:
<script type="text/template" id="this-is-the-id">
... template goes here ...
... the line below this is where my error's coming from ...
<%% _(<%= aNumber %>.times(function(){ console.log('hi'); });) %>
</script>
I'm getting the error Uncaught SyntaxError: Unexpected token <
. If I replace <%= aNumber %>
with an integer, it works as expected. Also, if I console.log(<%%= aNumber %>)
, it logs the correct number.
Does anybody know how I can accomplish something like this? I know that's kind of a sloppy way to organize my code, but this is just a quick little hack I'm putting together.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我不需要将
aNumber
包装在转义的<%%=
和%>
中,这为我解决了这个问题。Turns out I didn't need to wrap
aNumber
within the escaping<%%=
and%>
, and that fixed it for me.