Marionette.CompositeView how to pass a parameter to the template without using any model

Asked By: Anonymous

I am in the following situation.

When the collection.length = 0 I would like to pass a parameter to listTemplate in order to display a message in the listTemplate (no models are present!).
How can I achieve my goal?

Here’s my code.

var ListView = Marionette.CompositeView.extend({
    template: listTemplate,
    // some code
});

var itemView = Marionette.ItemView.extend({
    // some code
});

app.mainColumn.show(new ListView({
    collection: tasks,
    vent: myApp.vent
}));

Solution

Answered By: Anonymous

I guess you could redefine the serializeData method.

var ListView = Marionette.CompositeView.extend({
  template: listTemplate,
  serializeData: function(){
    viewData = { foo: 'foo' };
    if(this.collection.length == 0) viewData.bar = 'bar';
    return viewData;
  }
});

So in the template, this.bar is available (only if the collection is empty).

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno