javascript - Backbone and MVC - event bubbling -
i trying create tree visualization widget using backbone (and other libs) compliant mvc pattern.
i have node model , tree collection:
var node = backbone.model.extend({ defaults: { name : 'newnode', _id : null, parent_id: null, type : '' }, idattribute: '_id' }); var tree = backbone.collection.extend({ model: node }); and have view each:
nodeview - renders specific node's html
treeview - going on each node in collection , appending them div container.
var treeview = backbone.view.extend({ ... render: function () { this.collection.foreach(this.addnewnode, this); homecoming this; }, addnewnode: function(nodemodel){ var nodeview = new nodeview(); nodeview.render(); this.$el.find('.gnodes').append(nodeview.el); homecoming this; }, ... i have module acts controller (not backbone's router\controller) , there instantiate treeview tree collection.
var config = _.extend({}, defaults, options); var tree = new tree(); config.collection = tree; var treeview = new treeview(config); one of view events clicking on node edit info - since event happens on node made sense me have on nodeview.
var nodeview = svgview.extend({ ... events: { 'click [data-action="edittitle"]': 'editnodename' }, but have problem - how bubble event controller (so react it)?
my controller doesn't have instance of nodeview - treeview place create nodeview (for rendering).
should bubble event through treeview?
or should instantiate nodeview in controller?
note: tried simplify things didn't reveal of views , controller's code.
javascript backbone.js model-view-controller architecture event-handling
No comments:
Post a Comment