且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

openDatabase Hello World

更新时间:2022-11-08 14:46:37

你几乎就在那里,只有两件事:

You're almost there, there are only two things:


  1. 如果你想使用SQL语句回调,你应该提供给 executeSql 方法参数数组参数,即使你的查询没有需要任何参数。

  2. 您应该在循环中显示一个字段, result.rows.item(i)是一个对象包含属性作为表字段。

  1. The if you want to use the SQL statement callback, you should supply to the executeSql method the parameters array argument, even if your query doesn't need any param.
  2. You should get a field to show in your loop, result.rows.item(i) is an object that contains properties as your table fields.

您的选择将如下所示:

db.transaction(function(transaction) {
  transaction.executeSql('SELECT * FROM Table1',[], function (trx, result) {
    for (var i=0; i < result.rows.length; i++) {
      $('body').append(result.rows.item(i).Field1); // <-- getting Field1 value
    }
  }, errorHandler);
});

检查你的例子这里