Underscore.js - 未捕获的SyntaxError:意外的令牌)同时使用变量生成模板

Loj*_*Ibg 2 backbone.js underscore.js

我正在尝试用Underscore.js学习Backbone.js并遇到麻烦.我使用Grails作为服务器框架,因此Underscore.js语法<%=%>是不可能的.我想将其更改为{{}}样式.我的Javascripts在许多文件中分开,每个文件代表我需要的每个对象的视图或模型.这是我的视图的代码:

$(function () {

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

    APP = window.APP || {};

    APP.PlaceView = Backbone.View.extend({
        initialize:function () {
            this.render();
        },
        el:"#place-form",
        formTemplate:_.template($('#search-template').html()),
        render:function () {
            //Pass variables in using Underscore.js Template
            var variables = { street:"Ulica" };

            this.$el.html(this.formTemplate({ "street":"Ulica" }));
        }
    });

    var view = new APP.PlaceView();
});
Run Code Online (Sandbox Code Playgroud)

和模板:

<script type="text/template" id="search-template">
    <!-- Access template variables with {{ }} -->
    <label>{{ street }}</label>
    <input type="text" id="search_input"/>
    <input type="button" id="search_button" value="Search"/>
</script>
Run Code Online (Sandbox Code Playgroud)

此代码抛出Uncaught SyntaxError:Unexpected token)错误.但是当我删除_.templateSettings部分时,一切正常,但我没有变量.

非常感谢.

Kev*_*eel 9

我相信它因为这条线而显示错误:

<!-- Access template variables with {{ }} -->
Run Code Online (Sandbox Code Playgroud)

Underscore试图用不存在的变量替换它,从而引发错误.