javascript - patterns for storing/retrieving Backbone.js View instances associated with dom elements -
when create instances of views in backbone.js, assign root dom element becomes this.el within of view. within our backbone.js app have references view instance, it's easy work view. let's there's script on page doesn't have reference view instance, knows dom element represents view (this.el). there built-in way in backbone.js retrieve view instance dom element code doesn't have reference view instance can instance? i'd this:
var viewinstance = $("#rootelid").data("bb-myview");
i unaware of built-in functionality in backbone.js, thought i'd inquire in case 1 exist.
secondly, if isn't built backbone.js, way implement own functionality this? there patterns out there can copy?
thanks!
we utilize marionette layouts , regions accomplish type of functionality
the way create layout
var applayoutview = backbone.marionette.layoutview.extend({ template: "#layout-view-template", regions: { menu: "#menu", content: "#content" } }); var layoutview = new applayoutview(); layoutview.render();
display view in region
layoutview.menu.show(new menuview());
getting view region
var viewinstance = layoutview.menu.currentview // here can actual view instance
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.layoutview.md
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.region.md
thanks
javascript jquery backbone.js
No comments:
Post a Comment