backbone.js - Passing parameter in backbone and require.js -


how pass variable function in view file ? following call function in controller. have added view file in path earlier in code.

app.region.show(new view({templatepath:'app\view\myview.tpl'}); 

and here view file in want variable appear. option in backbone. 1 ugly way can think attached variable app object hate obvious reasons.

define(["app"], function(app) {   require([templatepath], function(sometplfile){     myview = backbone.marionette.itemview.extend({       template: sometplfile     });   });     return myview; }); 

help appreciated.

* adding edit pkyeck comment**

this not work ....

contentmain = backbone.marionette.itemview.extend({     initialize: function(values) {       require([values.tplname], function(maintpl){         this.var1 = maintpl;       });       },      template: this.var1,   }); 

the object pass view accesible in initialization of view. here can save attributes view.

something this:

myview = backbone.marionette.itemview.extend({     initialize: function(values) {         this.templatepath = values.templatepath;     },      anotherfunction : function(){         //this.templatepath can read here     } });  app.region.show(new view({templatepath:'app\view\myview.tpl'}); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -