【问题标题】:underscore _,template not recognize variables on template下划线_,模板无法识别模板上的变量
【发布时间】:2013-08-01 20:02:36
【问题描述】:

我正在使用下划线通过 require.js 和 text.js 加载 html 模板,如下面的代码:

      template: _.template(listItemTemplate)    

      , render: function () {
            $(this.el).html(this.template(this.model.toJSON));
            return this;
        }

tvListItemTemplate.html

<h4><%= _id%></h4>

如果我执行 console.log(this.model.toJSON()),它会打印以下内容:

但是控制台给了我这个错误:

我不明白为什么

【问题讨论】:

    标签: backbone.js underscore.js


    【解决方案1】:

    检查:

      $(this.el).html(_.template(listItemTemplate, this.model));
    

      template: function(x) {
          _.template(listItemTemplate, x);
      },
      render: function () {
            $(this.el).html(this.template(this.model));
            return this;
      }
    

    【讨论】:

      【解决方案2】:

      很抱歉,这是一个愚蠢的错误:

      $(this.el).html(this.template(this.model.toJSON()));

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-08
        • 2012-11-21
        • 1970-01-01
        相关资源
        最近更新 更多