And better, but time is tuned by the rudder compiler. The following code should be added to scripts that use use to compile your templates, not run-time. add this code to your compilation code, not at runtime - this is not an assistant). Then you can simply write {{model.title}}, and this expression will be automatically translated into model.get ('title') by the compiler. Of course, if the "model" is not a Backbone.Model, then it will access the json property as usual.
Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name) { var result = '((typeof(Backbone)!="undefined" && ' + parent + ' instanceof Backbone.Model) ? ' + parent + '.get("' + name + '") : ' + parent; if (/^[0-9]+$/.test(name)) { return result + '[' + name + '])'; } else if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) { return result + '.' + name + ')'; } else { return result + '[\'' + name + '\'])'; } };
source share