下划线_,模板无法识别模板上的变量

时间:2013-08-01 11:49:05

标签: backbone.js underscore.js

我使用下划线来加载带有text.js的require.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()),则会打印以下内容:

enter image description here

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

enter image description here

我不明白为什么

2 个答案:

答案 0 :(得分: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;
  }

答案 1 :(得分:0)

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

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