[英]Offline webapp. How to store data?
我想开发一个 webapp 来管理体育比赛。 它必须能够完全离线运行,在本地存储数据并在有可用互联网连接时通过 AJAX 在线发布结果 - 这可能是后天。
如何使用Javascript存储数据?
如果您支持现代浏览器,则可以使用HTML5 本地存储。
持久性本地存储是本机客户端应用程序相对于 Web 应用程序具有优势的领域之一。 对于本机应用程序,操作系统通常提供一个抽象层,用于存储和检索特定于应用程序的数据,如首选项或运行时状态。 根据平台约定,这些值可能存储在注册表、INI 文件、XML 文件或其他地方。 如果您的本机客户端应用程序需要除键/值对之外的本地存储,您可以嵌入自己的数据库、发明自己的文件格式或任何数量的其他解决方案。
例子
// Save data to a the current session's store
sessionStorage.setItem("username", "John");
// Access some stored data
alert( "username = " + sessionStorage.getItem("username"));
// Get the text field that we're going to track
var field = document.getElementById("field");
// See if we have an autosave value
// (this will only happen if the page is accidentally refreshed)
if ( sessionStorage.getItem("autosave")) {
// Restore the contents of the text field
field.value = sessionStorage.getItem("autosave");
}
// Check the contents of the text field every second
setInterval(function(){
// And save the results into the session storage object
sessionStorage.setItem("autosave", field.value);
}, 1000);
旧浏览器
使用Polyfill 。
您可以使用 HTML5 本地存储
对旧浏览器使用 polyfill https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills#web-storage-localstorage-and-sessionstorage
正是你想要的:
很多东西,但一个很酷的解决方案足以解决问题。 此外,CouchDB 这个东西非常简单,我敢打赌你会在一两天内阅读和学习所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.