Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Last active December 22, 2015 11:08
Show Gist options
  • Save Haraldson/6463393 to your computer and use it in GitHub Desktop.
Save Haraldson/6463393 to your computer and use it in GitHub Desktop.
define(
['marionette', 'model/publication', 'collection/issues', 'view/detail/publication', 'hbs!template/region/main-content'],
function(Marionette, PublicationModel, IssueCollection, PublicationCompositeView, MainContentRegionTemplate)
{
var MainContentRegionView = Marionette.ItemView.extend(
{
el: '#content',
// Use this template initially, with a spinner or something
template: MainContentRegionTemplate,
initialize: function()
{
this.getPublicationData('dagens', this.renderPublicationDetail);
},
getPublicationData: function(id, callback)
{
// get data, then
callback.call(this, cachedPublicationData);
},
renderPublicationDetail: function(data)
{
var publicationModel = new PublicationModel(
{
title: 'Dagens'
});
var publicationCompositeView = new PublicationCompositeView(
{
model: publicationModel,
collection: new IssueCollection(data.items)
});
console.log(publicationCompositeView.render().el);
// --> Perfectly fine HTML (as object), rendered with my specified templates etc.
// App.content is the region, which div#content is bound to -- the same region this itself is an initial view for
App.content.attachView(publicationCompositeView);
App.content.show(publicationCompositeView);
}
});
return MainContentRegionView;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment