jeudi 7 janvier 2016

How to working with Phonegap 5.4 and SQLite-Plugin

I'm trying to connect Phonegap 5.4 with SQLite on Android using SQLite-Plugin [http://ift.tt/1O3yCJy]

Firstly, I create my project and navigate to it using Phonegap CLI

$phonegap create sqlite-demo
$cd sqlite-demo

After that, I ran this command to install SQLite plugin:

$phonegap plugin add http://ift.tt/1O3yCJy --save

Finally, I used this below code to test [index.js file], but nothing happen:

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);        
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');
    var db = window.sqlitePlugin.openDatabase({name: "my.db"}, 
    function() {
        alert('Connected');
    },
    function(err) {
        alert('Error');
    });
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}
};

On the PhoneGap API [http://ift.tt/1OOxyNH] site I don't see any section about Storage or Database.

Is there any solution?

Aucun commentaire:

Enregistrer un commentaire