backbone.js - Is there another method, which exactly works as "onShow"? -
so, have 1 view(marionette itemview) render google maps based on address given input.this view being used in 3 places of application.where in 2 places,
case 1: i'm using regions show view(like: xyzregion.show(new mapview().render());),
case 2: i'm not using region, instead i'm doing like: this.el.innerhtml = new mapview().render();.
though marionette documentation has mentioned itemview, compositeview, collectionview, layoutview( docs) supports functionality of onshowwhen,if don't use region show map view, onshow not being triggered. after research came know "view won't trigger onshow, instead triggered region.
is there way trigger "onshow", though view not bieng shown region? or else there other method same "onshow"?
it sounds want write own custom implementation of pub-sub pattern.
since you're using marionette, can use
vent = new backbone.marionette.eventaggregator();
which object can broadcast / listen events.
alternatively, can define model instance , send view:
var view = backbone.view.extend({ initialize: function(){ this.model.on("change:address", this.render, this); }, render: function(){ //render } }); var somemodel = new somebbmodel(); var view = new view({ model: somemodel });
elsewhere in code:
//set address , trigger change model.set("address", "bla");
for activating google maps, necessary div in dom, why onshow callback might come in handy though.
panning map, can define method on view takes care of when address changes.
Comments
Post a Comment