我有一个表格,如下所示,在一个应用程序,我正在创建使用电子。我正在使用jQuery、Datatable和SQL.js:-
<table id="dataTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Code</th>
<th>Category</th>
<th>Hours</th>
<th>Cost</th>
<th>Billed</th>
<th>Description</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Date</th>
<th>Code</th>
<th>Category</th>
<th>Hours</th>
<th>Cost</th>
<th>Billed</th>
<th>Description</th>
</tr>
</tfoot>
</table>填充表的下列代码不能正常工作:
$(document).ready(function() {
var DB = null;
var t = $('#dataTable').DataTable();
$(".bottomMenuContainer").on("click", ".loadButton", function(e) {
var fs = require('fs');
var sql = require('sql.js');
var bfr = fs.readFileSync(__dirname + '/../data/EliteData.db');
DB = new sql.Database(bfr);
var stmt = DB.prepare("SELECT * FROM ProductEntries ORDER BY Category");
while(stmt.step()){
var row = stmt.getAsObject();
t.rows.add([row.Date, row.Code, row.Category, row.Hours, row.Cost, row.Billed, row.Description]).draw(false);
}
});
});对于第0行、第1列错误消息,我得到一个请求的未知参数'1‘,当它最终显示时,数据会分散在表上,并且在实际的数据库中有21个结果而不是3个结果。
知道发生了什么事吗?
发布于 2017-03-11 13:44:06
答案是创建一个数组并将数据推入数组中,然后将其添加到表中。那就画桌子。
while(stmt.step()){
var row = stmt.getAsObject();
var result = [];
result.push(row.Date);
result.push(row.Code);
result.push(row.Category);
result.push(row.Hours);
result.push(row.Cost);
result.push(row.Billed);
result.push(row.Description);
t.row.add(result);
}
t.draw(); 发布于 2017-03-11 13:53:05
很高兴看到你自己把它整理好了@Rec紧急:-)。虽然我自己也玩了一会儿,但我还是放弃了添加这样的单行:
let res = db.exec("SELECT * FROM ProductEntries");
table.rows.add(res[0].values).draw();这是一个工作JSFiddle,谢谢您对SQL.js的介绍,看起来很有趣!
https://stackoverflow.com/questions/42735490
复制相似问题