javascript - Backbone.js `model.destroy()` custom transitions? -


when use backbone's model.destroy(), seems automatically remove view dom.

is there way me use destroy() send delete request, remove view dom myself?

something like:

this.model.destroy({      wait: true,      success: function(){          $('#myelement').animate({              "height" : "0",              1000,              function(){$('#myelement').remove()}          });      }  });

you need override _oncollectionremove() in whichever collection view contains item views (documentation). function called when model removed collection, , it's what's destroying view. how choose override you, might easiest override animation function, maybe along following lines...

_oncollectionremove: function(model) {   var view = this.children.findbymodel(model);   var = this;   view.$('#myelement').animate({         "height" : "0",         1000,         function(){             that.removechildview(view);             that.checkempty();         }     }); } 

if prefer handle removal of view manually in destroy callback, override _oncollectionremove() contain empty function , whatever you'd in callback of delete request. i'd recommend approach describe above rather doing in destroy callback, though. eliminating function , handling it's responsibilities elsewhere in code interferes marionette's intended event flow. overriding function different ui effect preserves natural flow.

edit: user's previous answer (now deleted due downvoting) suggested might wise call destroy after ui effect completed. not approach reason op pointed out - if goes wrong destroy method, (for example, if remote server goes down) appears user if model deleted (the ui effect had completed) though server unreachable , model remains.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -