backbone.js - MarionetteJS - cannot reference this in template function -


i have view marionette itemview. access other parameters on view using "this" inside template function undefined , i'm unsure why.

define(['jquery', 'hbs!templates/template', 'backbone'],     function ($, template, backbone) {         "use strict";          return backbone.marionette.itemview.extend({              name: "depth",              el: ".card",              template: function(serializedmodel){                 var self = this; // self undefined, can't reference this.name, depth                  var data = {isdepth: true, cardtitle: self.name, injecthtml: template()};                   .... stuff ...                  return template();             }         });     } ); 

you can use underscore's bindall bind template marionetteitem view's whenever called . :

backbone.marionette.itemview.extend({     initialize: function(){         _.bindall(this, 'template');     },     template: function() {         //this refers parent object scope.     } }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -