如何清除骨干本地存储 [英] How to clear the backbone localstorage

查看:18
本文介绍了如何清除骨干本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript 看起来很简单,就是 localStorage.clear().

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 in the right direction on how to do it.

我正在考虑做这样的事情:

I was thinking about doing something like this:

localStorage.each(localStorage.delete(this))

localStorage.each(localStorage.delete(this))

除非 this 不会指向那个元素,是吗?

except this wouldn't point to that element would it?

推荐答案

很少有方法可以从 Collection 中执行此操作,但是无论您选择哪种方式,您都必须在每个模型上调用 destroy,这将运行同步并销毁它客户端和服务器端(localStorage 充当).

Few ways you can do this from the Collection, but whichever way you choose, you have to call destroy on each model, which will run sync and destroy it on both the client-side and server-side (which localStorage is acting as).

collection.each(function(model) {
      model.destroy();
    }
)

<小时>

更新

根据评论,这看起来不再有效了.由于这仍然被标记为答案,包括应该在下面工作的答案,每个 skcin7.

Per comments, doesn't look like this works anymore. Since this is still marked as the answer, including answer that should work below, per skcin7.

while ((model=collection.shift())) 
    { model.destroy();
}

这篇关于如何清除骨干本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆