java 脚本中的分页
我正在 chrome 扩展中工作,我想对使用 sqlite 查询动态填充的表进行分页。
我正在使用本教程进行分页并在 init 函数中进行一些修改
http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/
当我想获取的长度之后的表填充它,dom似乎还没有准备好,结果返回表长度为零,这是我的一些代码..
function ViewAllNotes(db){
var allListItems;
var cur = fromDateToString(new Date(),"date");
db.transaction(function(tx) {
tx.executeSql("SELECT NOTE_DESC,NOTE_DATE,NOTE_TIME FROM NOTES where NOTE_DATE = ? order by NOTE_TIME desc ",[cur],function(tx,result){
alert(result.rows.length);
for(i=0;i< result.rows.length;i++){
tr= "<tr>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_DESC']+"</td>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_TIME']+"</td>";
tr=tr+ "</tr>";
allListItems+=tr;
}
var tableContent= " <thead><tr><th id='activityHeader'>Activity</th> <th>Time</th></tr></thead>";
tableContent = tableContent+"<tbody>"+allListItems+"</tbody>";
$("table#notes").append(tableContent);
//$('#notes').dataTable();
},onError);
});
}
编辑 在 js 文件的开头,我这样编写
ViewAllNotes(db);
var rows = document.getElementById("notes").rows;
alert("rows "+rows.length);
,然后调用寻呼机类,但它也会以零警报?
I am working in chrome extension, I want to make paging for table which is fill dynamically using sqlite queries.
I am using this tutorial to make the paging and make some modification in init function
http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/
When I want to get the length of the table after filling it, the dom seems to be not ready and the result return as ZERO of table length, here's some of my code..
function ViewAllNotes(db){
var allListItems;
var cur = fromDateToString(new Date(),"date");
db.transaction(function(tx) {
tx.executeSql("SELECT NOTE_DESC,NOTE_DATE,NOTE_TIME FROM NOTES where NOTE_DATE = ? order by NOTE_TIME desc ",[cur],function(tx,result){
alert(result.rows.length);
for(i=0;i< result.rows.length;i++){
tr= "<tr>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_DESC']+"</td>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_TIME']+"</td>";
tr=tr+ "</tr>";
allListItems+=tr;
}
var tableContent= " <thead><tr><th id='activityHeader'>Activity</th> <th>Time</th></tr></thead>";
tableContent = tableContent+"<tbody>"+allListItems+"</tbody>";
$("table#notes").append(tableContent);
//$('#notes').dataTable();
},onError);
});
}
EDIT
At the begining of the js file I make like this
ViewAllNotes(db);
var rows = document.getElementById("notes").rows;
alert("rows "+rows.length);
then call the pager class, but also it alerts with zero ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL 调用是异步的。在 SQL 完成并触发回调之前,测试长度的代码将不会有可用的长度。
SQL calls are aysynchronous. Your code that tests for length will not have a length available until the SQL finishes and fires the callback.