我创建了一个列表视图,一旦从数据库中检索到数据,它就会显示在该列表视图中。 我想刷一下listview项目以从数据库中删除数据,并希望更新的数据显示在listview中。 我可以在这个..plz帮助中实现。
showRecords(),用于显示数据库中的数据
function showRecords()
{
var selectAllStatement = "SELECT * FROM list ORDER BY subject";
db.transaction(function (tx) {
tx.executeSql(selectAllStatement, [], function (tx, result) {
var dataset = result.rows.length;
var combinelist='';
for (var i = 0; i < dataset; i++)
{
res = result.rows.item(i);
var Lid=res.id;
var Lsubject=res.subject;
var Ldesc=res.desc;
var Ldate=res.date;
combinelist+='<li id="lists" rel="'+Lid+'" style="border-bottom:solid; background:#CFF">' + Lsubject + '<br>' + Ldesc + '<br>' + Ldate + '<br>' + '<a href="#" data-ajax="false" data-role="button" onclick="loadRecord('+Lid+');" class="ui-btn ui-corner-all ui-btn-inline" id="editbtn"> Edit</a></li>';
$("#showlist").html(combinelist).listview('refresh');
}
});
});
}
列表视图 ..
的代码<center><h2> To-Do List</h2></center>
<ul id="showlist" data-role="listview">
</ul>
Pageinit
$(document).on("pageinit","#pageone",function(){
localStorage.Lid=Lid;
alert(Lid);
$( "ul_showlist" ).on( "swiperight", swipeHandler );
function swipeHandler(){
alert("hello");;
var sql='DELETE FROM list WHERE id='+Lid+'';
db.transaction(function (tx) { tx.executeSql(sql,showRecords); alert("Delete Sucessfully"); });
}
});
答案 0 :(得分:0)
感谢能够滑动并删除记录..
$('#showlist #lists').on("swiperight",swiperight_list);
function swiperight_list(event)
{
var Lid=$(this).attr('rel');
var sql='DELETE FROM list WHERE id='+Lid+'';
db.transaction(function (tx) { tx.executeSql(sql);
alert("Delete Sucessfully"); });
}