html - 本地数据库存储默认数据

标签 html local-storage

我使用 HTML 5 Localstorage 开发了应用程序。

如何在初始化之前创建一个 TABLE 并填充 10000 多行 支持 HTML 5 的应用程序。

请提出一个模式。

最佳答案

var db = openDatabase('dbname', 'dbversion 1.0', 'description', 64*1024);
db.transaction(function (query){
   query.executeSql('CREATE TABLE IF NOT EXISTS tablename (id unique, value)');
   var rows = 10000, i;
   for(i=0; i < rows; i++){
      query.executeSql('INSERT INTO tablename (id, value) VALUES ('+ i + ', "Stackoverflow")');
   }

   query.executeSql('SELECT * FROM tablename', [], function (query, results) {
      for (i = 0; i < 5; i++) {
         alert(results.rows.item(i).text);
      }
   });
});

//Do magic with your webapp now

接受的查询是SQLite类型。检查official specification了解更多。

关于html - 本地数据库存储默认数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2391761/

相关文章:

html - 如何在 Angular 中用线条连接两个 div

javascript - IndexedDb 的范围是什么

javascript - 刷新时清除本地存储,解析和字符串化不起作用

reactjs - 如何存储到本地存储? ( react )

jquery - 我需要帮助完成滚动条上的垂直点导航吗?

html - 使用 flexbox 和 overflow hidden & scroll 在 Firefox 中不起作用?

javascript - ionic /Angular : Read and Write Array in Local Storage

javascript - 如何同步使用localForage

html - 删除左边框后如何防止文本向左移动?

html - 如何使按钮旁边的图像链接内联?