function(tx, rs) {
alert("update successfully");
});
});
return;
}
}
// 若文档不存在,则新建一个文档
if(rs.rows.length>0)
idx = rs.rows.item(rs.rows.length-1).idx + 1;
db.transaction(function(tx) {
tx.executeSql('INSERT INTO TextFiles VALUES(?, ?, ?)', [idx, fileTitle, fileContent],
function(tx, rs){
alert("save successfully: "+idx+"-"+fileTitle+ "-"+fileContent);
createFileIcon(idx);
},
function(tx, error) {
alert(error.source + "::" + error.message);
});
});
});
});
}
清单13首先在一个transaction中,首先判断用于存储文 本文档的表TextFiles是否存在,若不存在,则创建它。然后通过查询表TextFiles判断文本文档是否存在,若存在,则当前操作为更新操作,程 序将执行一条SQL语句,对当前文本文档进行更新。若不存在,则取当前最大文档id并加1作为新文档的id,并执行一条SQL语句,将文档信息,包括文档 id,以及标题和内容插入到数据库中,并于插入操作结束后的回调方法中,利用createFileIcon方法在桌面上为新文档创建一个文档图标。清单 14显示了 createFileIcon方法的具体过程。
清单 14.创建文档图标
-
function createFileIcon(fileId){
-
var iconHolder;
-
for(var i=1;i<=120;i++){// 查询第一个为空的位置
-
iconHolder = document.getElementById('iconHolder' + if(!iconHolder.firstChild ){
-
var text = document.createElement('img');
-
text.src = "images/text.gif";
-
text.id = fileId;
-
iconHolder.appendChild(text);
-
text.onclick = function(ev){
-
if(ev.currentTarget){
-
openApp('notebook');// 打开记事本应用程序
(责任编辑:12图资源库)