Skip to content

Instantly share code, notes, and snippets.

@kjirou
Created August 22, 2013 02:45
Show Gist options
  • Save kjirou/6302644 to your computer and use it in GitHub Desktop.
Save kjirou/6302644 to your computer and use it in GitHub Desktop.
It's bugged. findAll() can't find all localStorage keys of some Model. In the case, Backbone.LocalStorage requires to use Collection.
# Clear all data in localStorage about some model class.
@clearLocalStorage = (modelClass) ->
# Must create a model instance for to sync localStorage.records.
# (But is also a target that you want to delete it!
# Backbone.LocalStorage is not good so much...)
accessor = new modelClass
for modelAttrs in accessor.localStorage.findAll()
target = new modelClass(id: modelAttrs.id)
accessor.localStorage.destroy target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment