Stu*_*ple 5 templates upgrade backbone.js underscore.js underscore.js-templating
将我的Web应用程序从下划线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);
Run Code Online (Sandbox Code Playgroud)
});
Ish*_*now 17
从1.7.0 更改日志:
下划线模板不再接受初始数据对象._.template现在总是返回一个函数.
您需要将代码更改为以下内容:
$.get('tpl/listTpl.html', function(templates) {
var template = _.template(templates);
var result = template({list:app.collections.list.models});
that.$el.html(result);
});
Run Code Online (Sandbox Code Playgroud)