backbone.js - Backbone.Marionette - Accessing variables in the ItemView template or CompositeView template -
here want access variable or list of variables passed when initalizing new view corresponding template.
code example
creating list view
@taskit.module "tasks.list", (list, taskit, backbone, marionette, $, _) -> class list.newtask extends taskit.views.itemview template: jst["backbone/taskit/tasks/tasks/list/_templates/new_task"]
template above list view
<div id="new-task-form"> </div>
initializing itemview
view = new taskit.tasks.list.newtask project_id: "project_id"
here question how can access "project_id" variable template.
<%= project_id %> #is not working
in backbone can achieved
$(@el).html(@template({task: @model, project_id: "project_id"}))
how in marionette.js?
you can provide own method serialize data:
backbone.marionette.itemview.extend({ serializedata: function(){ var data = this.model.tojson(); data.project_id = this.project_id; return data; } });
Comments
Post a Comment