I’ve a problem with Backbone Marionette and ItemView rendering.
I need to pass a value from the Composite View to each of its Item View.
The value is contained correctly in the options array of the Item View, however, I cannot access it from the templateHelpers method.
So I tried to set it as value of my View but when I render the array it returns an “undefined” value.
The Composite View
var TableView = Backbone.Marionette.CompositeView.extend({
....
itemViewOptions: {
foo: "bar",
},
The Item View
var RowView = Backbone.Marionette.ItemView.extend({
template: RowTemplate,
tagName: "tr",
foo: "",
initialize: function(){
this.foo = this.options.foo;
},
templateHelpers: {
foo: function(){
return this.foo;
}
},
What I’m doing wrong? How can I access the value and fetch it to the template? Thank you.
In the
templateHelpersfunctions, thethisvariable is the object that was retured from theserializeDatamethod. To get theitemViewOptionsin to thetemplateHelpers, then, you need to modify theserializeDatamethod on your item view:This should make your data available in the
templateHelpers.