Build view with regions

By : Jumi

I use Marionette 3.0.

I have BlockView which could have variable number of regions. These regions are filled with BlockRegionViews which are CollectionViews (they would be in 2.x) and these views render further BlockViews. I would like to write a function that create a BlockView with it's regions already filled with (empty) BlockRegionViews, and than return this BlockView.

So i've written this code:

var blockView = new BlockView({model: blockModel});
var regions = blockModel.get('regions')
for(var i in regions) {
    var blockRegionModel = regions[i];
    var blockRegionView = new BlockRegionView({model: blockRegionModel});
    blockView.addRegion(blockRegionModel.get('position'), '...regiondefinition...');
    var region = blockView.getRegion(blockRegionModel.get('position'));
    // This is the line where i get the error.;
return blockView;

Of course my code is bad. Even the show function's name suggests that it's not the right function for me (since i don't want to show any views at this time), but I can't find anything like this in the documentation.

So my question is: How should i build a View with other views initialized in it's regions without rendering any of them?

By : Jumi


If I understand you correctly, you want to render views within a view, and not render anything until it all has been initialized.

Your blockModel and region handling in your description was a bit confusing, so I hope you can apply this to your case.

The documentation around a View's lifecycle is helpful.

var ChildView = Mn.View.extend({..});

var ParentView = Mn.View.extend({
  template: //..,
  onBeforeRender: function() {
    this.showChildView('reg1', new ChildView({model: someModel}));
  regions: {
    reg1: //..

In the above example the ChildView will be instantiated and attached to the ParentView before the ParentView has been rendered. However when the ParentView is rendered, the ChildViews will be instantiated and rendered in it's region.

You mentioned you don't want to render anything. That's a rare case, but you could instantiate child views outside of any rendering events.

var ChildView = Mn.View.extend({..});

var ParentView = Mn.View.extend({
  template: //..,
  initialize: function() {
    this.childView = new ChildView({model: someModel});

  // You can decide whenever you want to show the childView
  // and invoke this method.
  showTheChildView: function() {

  regions: {
    reg1: //..

Hopefully I understood your question correctly.

By : miphe

Assuming SQL Server 2005+, you can use ROW_NUMBER:

    SELECT  *,
            RN = ROW_NUMBER() OVER( PARTITION BY Foreign_ID 
                                    ORDER BY ID DESC)
    FROM dbo.YourTable
    WHERE [Date] >= '01-Jan-2016'   -- you need to use the right 
    AND [Date] <= '31-Dec-2016'     -- date format here
By : Lamak

This video can help you solving your question :)
By: admin