javascript - Build view with new child views in regions -
i use marionette 3.0.
i have blockview have variable number of regions. these regions filled blockregionviews collectionviews (they in 2.x) , these views render further blockviews. write function create blockview it's regions filled (empty) blockregionviews, , return blockview.
so i've written code:
var blockview = new blockview({model: blockmodel}); var regions = blockmodel.get('regions') for(var 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')); // line error. region.show(blockregionview); } return blockview;
of course code bad. show function's name suggests it's not right function me (since don't want show views @ time), can't find in documentation.
so question is: how should build view other views initialized in it's regions without rendering of them?
if understand correctly, want render views within view, , not render until has been initialized.
your blockmodel , region handling in description bit confusing, hope can apply case.
the documentation around a view's lifecycle helpful.
var childview = mn.view.extend({..}); var parentview = mn.view.extend({ template: //.., onbeforerender: function() { this.showchildview('reg1', new childview({model: somemodel})); }, regions: { reg1: //.. } });
in above example childview
instantiated , attached parentview
before parentview
has been rendered. when parentview
rendered, childviews
instantiated , rendered in it's region.
you mentioned don't want render anything. that's rare case, instantiate child views outside of rendering events.
var childview = mn.view.extend({..}); var parentview = mn.view.extend({ template: //.., initialize: function() { this.childview = new childview({model: somemodel}); }, // can decide whenever want show childview // , invoke method. showthechildview: function() { this.getregion('reg1').show(this.childview); }, regions: { reg1: //.. } });
hopefully understood question correctly.
Comments
Post a Comment