How to clear the backbone localstorage

前端 未结 4 601
栀梦
栀梦 2020-12-30 12:12

The javascript one seems pretty simple, just localStorage.clear().

Is there anything similar to that for the backbone localstorage, and if not, can someone point me

4条回答
  •  旧时难觅i
    2020-12-30 12:19

    Just iterating over the collection and calling destroy on each element is not save in any case. The reason is iterating over collection modified at the same time can produce unexpected results.

    It is better to first clone the collection and iterate over this clone. Checkout this.each not iterating through collection correctly for further details.

    Example:

    _.chain(Todos.models).clone().each(function(model){
      console.log('deleting model ' + model.id);
      model.destroy();
    });
    

提交回复
热议问题