如何清除amplify.store()?

Vla*_*ekh 6 javascript amplifyjs

我需要清除amplifyjs存储,删除所有键值.Smth类似于localStorage.clear().

提前致谢.

Dav*_*sey 8

amplifyjs的文档表明您可以通过将值存储null到该键来清除(删除)特定的存储密钥:

amplify.store( "MyKeyName", null );

我们可以使用以下命令获取所有当前存储密钥名称:amplify.store()然后使用jQuery $.each浏览列表并清除(删除)当前存储在" amplifyjs storage"中的每个项目:

$.each(amplify.store(), function (storeKey) {
    // Delete the current key from Amplify storage
    amplify.store(storeKey, null);
});
Run Code Online (Sandbox Code Playgroud)

您可以将此代码放入函数中并调用它或在某处内联使用它,但我可能会在运行时将函数添加到amplifyjs,例如:

amplify.clearStore = function() {
    $.each(amplify.store(), function (storeKey) {
        // Delete the current key from Amplify storage
        amplify.store(storeKey, null);
    });
};
Run Code Online (Sandbox Code Playgroud)

然后用它来调用它 amplify.clearStore();