2016-12-31 5 views
1

私はionicで簡単なクエリを作成するために結びついています。sqliteプラグインを使用して、いくつかのステートメント(挿入、更新、削除)を試しました。Cordova s​​qliteプラグイン - プロパティ 'item'を読み取ることができません

しかし、私はselect文の問題を取得

undefinedCannotが未定義

ノートのプロパティ「アイテムを」読み取りのプロパティ「アイテム」を読み込めません:私は、以前の車と呼ばれるテーブルを作成しました2列タイプとここ一年

は完全なコード

// Ionic Starter App 
 

 
// angular.module is a global place for creating, registering and retrieving Angular modules 
 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
 
// the 2nd parameter is an array of 'requires' 
 
var app = angular.module('starter', ['ionic']); 
 

 
app.run(function ($ionicPlatform) { 
 
    $ionicPlatform.ready(function() { 
 
     if (cordova.platformId === "ios" && window.cordova && window.cordova.plugins.Keyboard) { 
 
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
 
      // for form inputs) 
 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
 

 
      // Don't remove this line unless you know what you are doing. It stops the viewport 
 
      // from snapping when text inputs are focused. Ionic handles this internally for 
 
      // a much nicer keyboard experience. 
 
      cordova.plugins.Keyboard.disableScroll(true); 
 
     } 
 
     if (window.StatusBar) { 
 
      StatusBar.styleDefault(); 
 
     } 
 

 

 
     // Select from table 
 

 

 
     var db = null; 
 

 
     document.addEventListener('deviceready', function() { 
 
      //db = window.sqlitePlugin.openDatabase({ name: 'demo.db', location: 'default' }); 
 
      db = window.openDatabase("localDB", "1.0", "Cordova Demo", 200000); 
 

 
      db.transaction(function (tx) { 
 
       var query = 'SELECT * FROM cars'; 
 
       tx.executeSql(query, [], function (res) 
 
       { 
 
        alert(res.rows.item(0).type); 
 

 
       }); 
 
      
 
       
 
       
 

 
      }) 
 

 
     }); 
 

 

 

 

 
    }); 
 
});
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
 
    <title></title> 
 

 
    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
 
    <link href="css/style.css" rel="stylesheet"> 
 

 
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
 
    <link href="css/ionic.app.css" rel="stylesheet"> 
 
    --> 
 

 
    <!--For users deploying their apps to Windows 8.1 or Android Gingerbread, platformOverrided.js 
 
    will inject platform-specific code from the /merges folder --> 
 
    <script src="js/platformOverrides.js"></script> 
 

 
    <!-- ionic/angularjs js --> 
 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
 

 
    <!-- cordova script (this will be a 404 during development) --> 
 
    <script src="cordova.js"></script> 
 

 
    <!-- your app's js --> 
 
    <script src="js/app3.js"></script> 
 
    </head> 
 
    <body ng-app="starter"> 
 

 
    <ion-pane> 
 
     <ion-header-bar class="bar-stable"> 
 
     <h1 class="title">SQLITE DATABASE </h1> 
 
     </ion-header-bar> 
 
     <ion-content> 
 
    
 

 
     </ion-content> 
 
    </ion-pane> 
 
    </body> 
 
</html>
です

答えて

1

これを試してみてください:

tx.executeSql(query, [], function (tx,res){ 
     alert(res.rows.item(0).type); 
}); 
+0

は、それが動作する、ありがとうございます! .. 問題の理由を私に説明することができます.. – saifaldeen

+1

あなたはようこそ! executeSqlの最初のパラメータは、前に一歩前にしたように、いくつかのsqlite文を実行できるオブジェクトです。 2番目のパラメータは、実際のステートメントの結果を保持します。これは、 "tx"オブジェクトからexecuteSqlを呼び出すときに当てはまりますが、 "db"オブジェクトから呼び出すときには、最初のパラメータはすでにクエリの結果です([here](https:// github。 com/litehelpers/Cordova-sqlite-storage/blob/storage-master/README.md)を参照してください。それが役に立てば幸い! PS:正しく答えてください;) – Blauharley

+0

PS:そこにはたくさんのdb-pluginsがありますが、executeSqlはすべてのプラグインで同様の動作をするかどうかは保証されません。 – Blauharley

関連する問題