javascript - CompositeView not get "remove" event when extending the Backbone collection -
here steps:
declare extended collection of backbone colleciton: extenedcollection = $.extend({}, backbonecollection, decorator);
build composite view extended collection.
do extenedcollection.remove(xmodel);
expected result: composite view catch remove event , remove relevant item view composite view.
actual result: backbone's remove() function fire "remove" event. marionette in _initialevents listening on "remove" event, not catch remove event when fired, , therfore not execute function "removeitemview".
comment: code extenedcollection = $.extend(backbonecollection, decorator); works fine. must create new object when extending original backbone collection.
help?
why not use built in backbone.collection.extend
functionality? designed use case talking about.
// extend backbone types backbone.extend function var mycollectiontype = backbone.collection.extend(mydecorator); var mycollection = new mycollectiontype(models); var mycompositeview = new myawesomecompositeview({collection : mycollection}); // not necessary. mycompositeview.onitemremoved = function () { console.log(arguments); }; mycollection.remove(mymodel); // event handled composite view
Comments
Post a Comment