模板错误升级到下划线1.7

时间:2014-08-29 14:37:00

标签: templates backbone.js underscore.js upgrade underscore.js-templating

将我的网络应用程序从下划线1.6升级到1.7时,收到以下错误“列表未定义”。使用下划线1.6时效果很好。有什么想法吗?

//acquire the list template
$.get('tpl/listTpl.html', function(templates) {

//run underscore js on the list template and pass in the full collection of models
var template = _.template(templates, {list:app.collections.list.models});

//load the underscore template into the DOM
that.$el.html(template);

});

1 个答案:

答案 0 :(得分:16)

从1.7.0 changelog

  

下划线模板不再接受初始数据对象。 _.template现在总是返回一个函数。

您需要将代码更改为以下内容:

$.get('tpl/listTpl.html', function(templates) {
  var template = _.template(templates);
  var result = template({list:app.collections.list.models});
  that.$el.html(result);
});