每次插入、删除或更新数据时,我都需要重新启动我的应用程序。数据正在正确插入和删除......但不知道为什么我每次都需要重新启动我的应用程序才能获得效果。
我想为此应用程序使用文件结构。
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="js/lawnchair.js"></script>
<script type="text/javascript" charset="utf-8" src="js/dom.js"></script>
<script>
$(function(e) {
var details = Lawnchair({name:'details',adapter:'dom'},function(e){
//this.nuke();
});
details.all(function(data){
for(var i = 0; i<data.length;i++)
{
//alert(data.length);
var id = i + 1;
//alert(id);
document.getElementById("id").value = id;
var listdiv = document.createElement('li');
listdiv.setAttribute('id','listdiv' + i);
listdiv.innerHTML = "ID : " + data[i].value.id + " | " + "Name : " + data[i].value.name + " | " + "Desc : " + data[i].value.desc;
$('#show_list').append(listdiv);
}
});
$('#save').click(function(e){
//alert($.now());
var obj1 = {id:$('#id').val(),name:$('#name').val(),desc:$('#desc').val()};
//alert("listdiv" + obj1.id);
details.save({key:"listdiv" + obj1.id,value:obj1});
alert("Data Saved Successfully");
//location.reload();
});
$('#del').click(function(e){
if(document.getElementById("name").value != "")
{
var id = document.getElementById("id").value;
details.remove("listdiv" + id,function(obj1){
$("input:text").val("");
document.getElementById("show_list").innerHTML = "";
alert("Data Removed Successfully");
});
}
else
{
alert("Please Select Data");
return false;
}
});
$('li').live('click',function(e){
//alert(this.id);
details.get(this.id,function(obj){
document.getElementById("id").value = obj.value.id;
document.getElementById("name").value = obj.value.name;
document.getElementById("desc").value = obj.value.desc;
});
});
});
</script>
</head>
<body>
</body>
</html>