1

I'm using the localstorage adapter by jeromegn https://github.com/jeromegn/Backbone.localStorage..

I am wondering if there's any way to delete an item with in local storage by a where clause, using his adapter..

Within my collection I have

localStorage: new Store("stuff")

And then within a separate view, I need something like this..

Collection.destroy({name = "Danny"}); - Which will find the row with danny and delete it..

Do I need to change his destroy function?

destroy: function(model) {
    this.localStorage().removeItem(this.name+"-"+model.id);
    this.records = _.reject(this.records, function(record_id){return record_id == model.id.toString();});
    this.save();
    return model;
  }

How can I go about doing this, cheers!

4

1 回答 1

2

您可以使用

var name = "Danny";

var _name = Collection.find( function( model ) {
     return model.get("Name") === name;
});

_name.destroy();
于 2012-08-31T11:49:57.637 回答