错误“未捕获的SyntaxError:意外的令牌LT;在underscore.js“ [英] Error 'Uncaught SyntaxError: Unexpected token < in underscore.js'

查看:1698
本文介绍了错误“未捕获的SyntaxError:意外的令牌LT;在underscore.js“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code,

HTML:

<script type="text/html" id="test_temp">
    <div class="row" id="opportunityList">
        <% _.each(ops, function(option){
            <div class="span12">
                <div class="well basicInformation">
                    <div class="row">
                        <div class="span4 opportunityName" >
                            <h4><%= option.company_name %></h4>
                        </div>
                        <div class="span4 pull-right">
                            <ul class="inline">
                                <li class="dealGrade">
                                    <span><%= option.dealGrade %></span>
                                    <span class="subheader">Deal Grade</span>
                                </li>
                                <li class="estimateddevices">
                                    <span><%= option.devices %></span>
                                    <span class="subheader">Devices</span>
                                </li>
                                <li class="accountValue">
                                    <span><%= option.accountValue %></span>
                                    <span class="subheader">Account value</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        });
        %>
    </div>
</script>

SCRIPT:

testView = Backbone.View.extend({
    initialize: function(){
        this.render();
    },

    render: function(){
        var ops = [
            {dealGrade: '50%', devices: 123, accountValue: '20%', company_name: 'Kyocera', rep_name: 'James Kogg', rep_designation: 'Sales Rep', proposalCount: 2},
            {dealGrade: '75%', devices: 215, accountValue: '41%', company_name: 'Flipkart', rep_name: 'Christina Kogg', rep_designation: 'MD', proposalCount: 0}
        ]

        var template = _.template($("#test_temp").html(), ops);

        this.$el.append(template);
    }
});

var test_view = new testView({ el: $("#viewport .container") });

我收到此错误信息:

I get this error message:

未捕获的SyntaxError:意外的令牌LT;在underscore.js

Uncaught SyntaxError: Unexpected token < in underscore.js

我在做什么错了?

推荐答案

你没有关闭&LT;%围绕 _每或打开模板标签为 _每个的结束});

You're not closing the <% around the _.each or opening the template tag for the _.each's closing });:

<script type="text/html" id="test_temp">
   <div class="row" id="opportunityList">
     <% _.each(ops, function(option){ %>
       ...
     <% }); %>
   </div>
</script>

下划线的模板引擎是pretty头脑简单,它只是做了一点简单的文本的争论把你的模板内而外成JavaScript code。

Underscore's template engine is pretty simple minded, it just does a bit of simple text wrangling to turn your template inside-out into JavaScript code.

此外,模板函数希望其作为键/值对数据(即JavaScript对象),所以你需要给你的 OPS 名称:

Also, the template function wants its data as key/value pairs (i.e. a JavaScript object) so you'll need to give your ops a name:

var template = _.template($("#test_temp").html(), { ops: ops });

这篇关于错误“未捕获的SyntaxError:意外的令牌LT;在underscore.js“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆