2012-08-31 58 views
1

我使用localStorage的適配器通過jeromegn https://github.com/jeromegn/Backbone.localStorage ..骨幹本地存儲,由現場刪除行

我想知道是否有任何的方式與在本地存儲的where子句中刪除項目,用他的適配器..

在我的收藏我有

localStorage: new Store("stuff") 

然後一個單獨的視圖中,我需要的是這樣的..

Collection.destroy({name = "Danny"}); - 這將找到與丹尼行並刪除它..

我需要改變他的破壞功能嗎?

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; 
    } 

我該怎麼去做這個,乾杯!

回答

2

您可以使用

var name = "Danny"; 

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

_name.destroy();