Here i want to access a variable or a list of variables which is passed when initalizing a new view from its corresponding template.
Creating a 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 for the above list view
<div id="new-task-form">
</div>
Initializing the ItemView
view = new Taskit.Tasks.List.NewTask
project_id: "project_id"
Here my question is how can i access the "project_id" variable from its template.
<%= project_id %> #is not working
In Backbone it can be achieved by
$(@el).html(@template({task: @model, project_id: "project_id"}))
You can provide your own method to serialize data:
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.itemview.md#itemview-serializedata
Backbone.Marionette.ItemView.extend({
serializeData: function(){
var data = this.model.toJSON();
data.project_id = this.project_id;
return data;
}
});
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