How to clear the entire model

37 views
Skip to first unread message

Andrew Symington

unread,
May 15, 2013, 5:40:52 AM5/15/13
to batm...@googlegroups.com
Hi There

I'm using LocalStorage to temporarily store my model data. I would like my app's constructor to clear all records (on storage and in the model). Is there a quick way to achieve this? I see that the clear() method in Batman.Model just clears the identity map, but the data remains in local storage. Is there any way to clear the local storage as well?

Cheers
Andrew

Jeff Berg

unread,
May 15, 2013, 11:14:23 AM5/15/13
to batm...@googlegroups.com
Andrew,

You can clear all local storage using localStorage.clear(). http://stackoverflow.com/questions/7667958/clear-localstorage

If you need to clear all for a particular model then I believe you will need to iterate over each object and destroy it.

Jeff


Andrew

--
You received this message because you are subscribed to the Google Groups "batman.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to batmanjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jeff Berg
Owner/Developer
Ministry Centered Technologies
=================================
REVOLUTIONIZE the way you plan your SERVICES at planningcenteronline.com
REVOLUTIONIZE the way you plan your EVENTS at smartevents.com

Andrew Symington

unread,
May 16, 2013, 4:43:59 AM5/16/13
to batm...@googlegroups.com, je...@ministrycentered.com
Hi Jeff

This is what I've been doing so far, and it seems to work, even though its a bit clunky.
records = MyApp.MyModel.get('all')
records.forEach (record) ->
  MyApp.MyModel.find(record.get('_id'), (err) ->
    if (err)
      console.log "Cannot find record " + record.get('_id')
    ).destroy()
MyApp.MyModel.clear()

So, from what I can tell, this is probably a simpler solution.

MyApp.MyModel.clear()
window.localStorage.clear()

Thanks for the help!

Cheers
Andrew
Reply all
Reply to author
Forward
0 new messages