本文介绍了与Underscore.js模板轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图用underscore.js模板,模板在Rails 2.3应用程序,它做的不可以的jammit作为资产打包。

I was trying to use underscore.js templates for templating in a rails 2.3 app which does not have jammit as an asset packager.

下面是一个简单的模板:

Here is the simple Template:

<script type="text/template" id="q-template">
    <div class="current-body">
        <span class="q-index"><%= title %></span>
        <span class-"q-text"><%= body %></span>
    </div>
</script>

Rails的尝试解析这些为雇员再培训局变量,会引发ArgumentError。我要如何强调模板与在这种情况下轨很好玩呢?我在哪里去了?

Rails tries to parse these as erb variables and throws an ArgumentError. How do I get underscore templates to play nicely with rails in this case? Where am I going wrong?

推荐答案

使用一些其他的分隔符,而不是&LT;%=%GT; 。例如,用胡子样式括号 {{=}} (插值)和 {{}} (评估),这个地方添加到您的javascript:

Use some other delimiters instead of <%= %>. For example, to use mustache-style brackets {{= }} (interpolate) and {{ }} (evaluate), add this somewhere to your javascript:

_.templateSettings = {
    interpolate: /\{\{\=(.+?)\}\}/g,
    evaluate: /\{\{(.+?)\}\}/g
};

这篇关于与Underscore.js模板轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:49