将主干响应嵌入 Rails 中的下划线模板中?

发布于 2024-12-12 15:53:31 字数 607 浏览 2 评论 0原文

我正在将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2024-12-19 15:53:32

事实证明,我不需要将 aNumber 包装在转义的 <%%=%> 中,这为我解决了这个问题。

Turns out I didn't need to wrap aNumber within the escaping <%%= and %>, and that fixed it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文