Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript y初始化,此处需要Cordova。 var元素=document.getElementById(“deviceready”); myDB=window.sqlitePlugin.openDatabase({ 名称:“mySQLite.db”, 位置:“默认” }); element.innerHTML='设备就绪'; element.className+='ready'; }; });_Javascript_Angularjs_Sqlite_Cordova_Ionic - Fatal编程技术网

Javascript y初始化,此处需要Cordova。 var元素=document.getElementById(“deviceready”); myDB=window.sqlitePlugin.openDatabase({ 名称:“mySQLite.db”, 位置:“默认” }); element.innerHTML='设备就绪'; element.className+='ready'; }; });

Javascript y初始化,此处需要Cordova。 var元素=document.getElementById(“deviceready”); myDB=window.sqlitePlugin.openDatabase({ 名称:“mySQLite.db”, 位置:“默认” }); element.innerHTML='设备就绪'; element.className+='ready'; }; });,javascript,angularjs,sqlite,cordova,ionic,Javascript,Angularjs,Sqlite,Cordova,Ionic,我找到了解决方案 只要在index.js中的函数上方声明变量名,它就会在整个控制器中加载DB名称 var-myDB; (功能(){ “严格使用”; document.addEventListener('devicerady',ondevicerady.bind(此),false); 函数ondevicerady(){ //处理Cordova暂停和恢复事件 document.addEventListener('pause',onPause.bind(this),false); document.

我找到了解决方案

只要在index.js中的函数上方声明变量名,它就会在整个控制器中加载DB名称

var-myDB;
(功能(){
“严格使用”;
document.addEventListener('devicerady',ondevicerady.bind(此),false);
函数ondevicerady(){
//处理Cordova暂停和恢复事件
document.addEventListener('pause',onPause.bind(this),false);
document.addEventListener('resume',onResume.bind(this),false);
//TODO:已加载Cordova。请在此处执行任何需要Cordova的初始化。
var元素=document.getElementById(“deviceready”);
myDB=window.sqlitePlugin.openDatabase({
名称:“mySQLite.db”,
位置:“默认”
});
element.innerHTML='设备就绪';
element.className+='ready';
};

});我找到了解决方案

只要在index.js中的函数上方声明变量名,它就会在整个控制器中加载DB名称

var-myDB;
(功能(){
“严格使用”;
document.addEventListener('devicerady',ondevicerady.bind(此),false);
函数ondevicerady(){
//处理Cordova暂停和恢复事件
document.addEventListener('pause',onPause.bind(this),false);
document.addEventListener('resume',onResume.bind(this),false);
//TODO:已加载Cordova。请在此处执行任何需要Cordova的初始化。
var元素=document.getElementById(“deviceready”);
myDB=window.sqlitePlugin.openDatabase({
名称:“mySQLite.db”,
位置:“默认”
});
element.innerHTML='设备就绪';
element.className+='ready';
};

});我遇到同样的问题并设法解决:我遇到同样的问题并设法解决:我遇到同样的问题并设法解决:我遇到同样的问题并设法解决:
TypeError: Cannot read property 'transaction' of null: ionic.bundle.js:19387
<ion-view view-title="Search" ng-controller="AppCtrl2">
  <ion-content>
    <ion-list>
      <ion-item ng-repeat="item in resultados">
        Hello, {{item}}!
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>
var db = null;

angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])

.run(function($ionicPlatform,$cordovaSQLite) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
    db = $cordovaSQLite.openDB({ name: "my.db" });
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
    query = "INSERT INTO people (firstname, lastname) VALUES (?,?)";
    $cordovaSQLite.execute(db, query, ["Sumit", "Pal"]).then(function(res) {
        console.log("INSERT ID -> " + res.insertId);
      });
    $cordovaSQLite.execute(db, query, ["Sumti2", "Pal"]);
  });
})
.controller('AppCtrl2', function($scope,$ionicPlatform,$cordovaSQLite) {

 $ionicPlatform.ready(function() {

    function getCat() {
      var selectQuery = "SELECT * FROM people";
      $cordovaSQLite.execute(db, selectQuery).then(function(result) {
      nombres = []; 
      for(var i=0; i<result.rows.length; i++){
          nombres.push({"nombre":result.rows.item(0).firstname});
        }
      })
    }
    $scope.resultados =  getCat();       
  })

});
$scope.select = function(lastname) {
        var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
        $cordovaSQLite.execute(db, query, [lastname]).then(function(res) {
            if(res.rows.length > 0) {
                var message = "SELECTED -> " + res.rows.item(0).firstname + " " + res.rows.item(0).lastname;
                alert(message);
                console.log(message);
            } else {
                alert("No results found");
                console.log("No results found");
            }
        }, function (err) {
            alert(err);
            console.error(err);
        });
    }
ionic build android
adb install -r platforms/android/ant-build/CordovaApp-debug.apk
dbConnection :function(){
    if (window.cordova) {
        dbconn = $cordovaSQLite.openDB({ name: "my.db" , location: 'default'}); 
        $cordovaSQLite.execute(dbconn, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
    }
    else{
        dbconn = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100);
        $cordovaSQLite.execute(dbconn, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
    }
    return dbconn;
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
   $scope.resultados =  getCat();
}
db = $cordovaSQLite.openDB({ name: "my.db" });
db = $cordovaSQLite.openDB({ name: "my.db", location:"default" });