phonegap 就不多做介绍了,在此你看到的文章的分类就略知其作用了。
本节介绍的phonegap的存贮的实现,比较奇怪的是我始终都没有找到其存储文件存放的目录在哪里,原本以为会在/data/data/app package/databases/ 其实不然,在stackoverflow,gmailgroup里面都提问了,尚未得到有效的答复。希望有经验的朋友能够在此留言告知于我,表示感谢!
其实就两个页面,实现CRUD的操作,so easy!
index.html
<!DOCTYPE html>
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Populate the database
//
function populateDB(tx) {
//tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id integer PRIMARY KEY autoincrement, title text,content text)');
//tx.executeSql('INSERT INTO DEMO (title,content) VALUES ("First row","first content")');
//tx.executeSql('INSERT INTO DEMO (title,content) VALUES ("Second row","second content")');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
var len = results.rows.length;
var div = "<table>";
console.log("DEMO table: " + len + " rows found.");
for ( var i = 0; i < len; i++) {
console.log("Row = " + i + " ID = " + results.rows.item(i).id
+ " Data = " + results.rows.item(i).title);
div += "<tr><td>" + i + "</td>" + "<td>" + results.rows.item(i).id
+ "</td>" + "<td>" + results.rows.item(i).title + "</td>"
+ "<td>" + results.rows.item(i).content + "</td>"
+ "<td><a href='#' onclick='deletes("
+ results.rows.item(i).id + ");'>delete</a></td></tr>";
}
div += "</table>";
document.getElementById("div").innerHTML = div;
}
var index;
function deletes(index_) {
index = index_;
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(deletes_, errorCB, successCB);
}
function deletes_(tx) {
tx.executeSql('delete FROM DEMO where id = ' + index, [], querySuccess,
errorCB);
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: " + err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
console.log("Success processing SQL: ");
}
// Cordova is ready
//
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
function display() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
}
function search() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(search_, errorCB, querySuccess);
}
function search_(tx) {
var key = document.getElementById("keywords").value;
console.log("key: " + key);
tx.executeSql("SELECT * FROM DEMO where title like '%" + key + "%'",
[], querySuccess, errorCB);
}
</script>
</head>
<body>
<h1>Example</h1>
Database
[url=add.html]Add[/url]
<input name="keywords" id="keywords" placeholder="search something">
<input type="submit" onclick="search();" />
<div id="div"></div>
</body>
</html>
add.html
<!DOCTYPE html>
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
function inster(){
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(inster_, errorCB, successCB);
}
function inster_(tx){
var t = document.getElementById("title").value;
var c = document.getElementById("content").value;
tx.executeSql("INSERT INTO DEMO (title,content) VALUES ('"+t+"','"+c+"')");
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
console.log("Success processing SQL: ");
}
</script>
</head>
<body>
<h1>Example</h1>
Database - Add
Title:
<input type="text" id="title"/>
Content:
<input type="text" id="content"/>
<input type="submit" id="submit" value="submit" onclick="inster();"/>
</body>
</html>
代码较为简单就不多做介绍了,附件中含工程源码。遇到问题敬请留言。
分享到:
相关推荐
PhoneGap - API 中文说明 Accelerometer 加速度计 Camera 相机 Capture 捕捉 Compass 指南针 Contacts 联系人 Device 设备 Events 活动 File 文件 Geolocation 地理位置 Media 媒体 Network 网络 Notification 通知...
PhoneGap - API 中文说明 Accelerometer 加速度计 Camera 相机 Capture 捕捉 Compass 指南针 Contacts 联系人 Device 设备 Events 活动 File 文件 Geolocation 地理位置 Media 媒体 Network 网络 Notification 通知...
科尔多瓦的厨房水槽/样板-PhoneGap-Babel-React-Hotloader-Webpack-Framework7-Firestore-FontAwesome 具有原生外观的即用型混合移动应用程序的模板。 预习 安卓 的iOS 工具类 参见下文 编译为iOS和Android应用 ...
科尔多瓦-sqlite-storage-js Javascript库可轻松使用cordova-sqlite-storage插件 配置 var db_config = { name : 'your_db_name.db' , location : 'default' } ; 用法 db_query function success_callback ( ) {...
适用于Cordova / PhoneGap的跨平台SQLite存储插件-cordova-sqlite-storage插件版本 具有基于HTML5 / 的本机SQLite组件,适用于以下平台: 浏览器 安卓 的iOS macOS(“ osx”平台) Windows 10(UWP)桌面和移动...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android....
和localstorage差不多,但是这个有过期时间,时间过期后会移除缓存的内容,在过期前关闭浏览器和页面都不会导致缓存内容被移除。
It then moves on to concepts such as file system, storage, and local database, the book effectively lays a solid base for advanced topics. By working through the steps in each chapter, you will ...
Chapter 5: Using Device Storage and the Files API Chapter 6: Using the Contacts and Camera APIs Chapter 7: Accessing the Device Sensors and Locations API Chapter 8: Advanced PhoneGap Chapter 9: ...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android....
PhoneGap开发必备 PhoneGap Mobile Application Development Cookbook Preface 1 Chapter 1: Movement and Location: Using the Accelerometer and Geolocation Sensors 7 Introduction 7 Detecting device ...
cordova-plugin-network-information 1.0.1“网络信息”#查看网络状态cordova-plugin-whitelist 1.0.0“ Whitelist”#默认情况下cordova-sqlite-storage 0.7.9“ Cordova sqlite storage plugin” ...
Take advantage of client-side data storage with apps that run even when the Android device is offline Use PhoneGap to hook into advanced Android features -- including the accelerometer, geolocation,...
Phonegap \ Cordova的简单文件选择库 特征: 支持口罩 在许多情况下都有回调(您可以使用它们进行一些有趣的操作) 可以设置样式(包括默认样式) 未来发展: 放弃点击,取而代之的是快速点击 例子: var path ...
Take advantage of client-side data storage with apps that run even when the Android device is offline Use PhoneGap to hook into advanced Android features — including the accelerometer, geolocation, ...
Chapter 2 Storage, Databases, Geolocation, and Offline Apps Chapter 3 Introduction to CSS3 Chapter 4 Meta Tags and Media Queries Chapter 5 HTML5 Mobile Apps with PhoneGap Chapter 6 ...
Sunasara,我正在使用媒体捕获插件做类似的事情,并得到了照片uri(类似这样的文件:/CapturedImagesCache/WP_20150424_001.jpg)。 插件创建了一个名为CaptureddImagesCache的文件夹并将图片保存在其中。...