When upgrading my web app from underscore 1.6 to 1.7, I receive the following error "list is not defined". When using underscore 1.6 it works perfectly. Any ideas?
//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);
});
The _. template() function is an inbuilt function in the Underscore. js library of JavaScript which is used to compile JavaScript templates into functions that can be evaluated for rendering.
Adding Underscore to a Node. Once added, underscore can be referred in any of the Node. js modules using the CommonJS syntax: var _ = require('underscore'); Now we can use the object underscore (_) to operate on objects, arrays and functions.
The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
From the 1.7.0 changelog:
Underscore templates no longer accept an initial data object. _.template always returns a function now.
You will need to change your code to the following:
$.get('tpl/listTpl.html', function(templates) {
var template = _.template(templates);
var result = template({list:app.collections.list.models});
that.$el.html(result);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With