javascript - Checking for any dirty Backbone model data within collection -


i have requirement "nag" user unsaved changes when switch between different backbone collection models (by clicking on table row). i've googled "check backbone model dirty data" (for instance) , not found definitive.

i accomplished using underscore's "some" , isequal functionality, in manner such following, "some()" being sufficient determine if there any un-saved changes (as opposed precise changes might be), in particular because model attribute array of objects.

var anydirty = _.some(mycollection.models, function(model) {     return !_.isequal(model.get('nodes'), model.previousattributes()['nodes]); }); 

i new backbone , wondering if accepted sort of approach adhoc checking dirty model data. or, backbone provide sort of built in functionality purpose, initial attempts @ googling did not reveal?

i have attribute need monitor in addition 'nodes', i'm switching using changedattributes(): http://backbonejs.org/#model-changedattributes:

var anydirty = _.some(mycollection.models, function(model) {     return model.changedattributes(); }); 

what may make imperfect solution seems return object of changedattributes if attribute got changed it's original value. seems need in long run take snapshot of original data , compare against that. still though, using model.changedattributes() more concise alternative first posted.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -