我想通过ionic做一个简单的查询,我使用了sqlite插件,我尝试了几个语句(插入,更新,删除)都可以正常工作。

但是我选择语句有问题


无法读取未定义的属性“ item”无法读取未定义的属性“ item”


注意:我以前创建了一个名为cars的表,该表具有两列类型和年份

这是完整的代码



// 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>

最佳答案

试试这个:

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

关于sqlite - Cordova s​​qlite插件-无法读取属性“item”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41408782/

10-08 21:53