underscore _,template not recognize variables on template

旧巷老猫 提交于 2019-12-11 19:29:28

问题


I´m using underscore to load a html template with by require.js with text.js, like code bellow:

      template: _.template(listItemTemplate)    

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

tvListItemTemplate.html

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

If i do console.log(this.model.toJSON()) it prints the following:

But the console give me this error:

I don´t understand why


回答1:


Check with:

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

or

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



回答2:


Sorry for that but it was a own stupid error in:

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



来源:https://stackoverflow.com/questions/17993238/underscore-template-not-recognize-variables-on-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!