<form>
<br/>
<label for="products1">Product Name:</label>
<input type="text" name="pdt" id="product" /><br/><br/>
<label for="quantity">Quantity : </label>
<input type="number" name="qty" id="quantity" /><br/><br/>
<label for="price">Price :</label>
<input type="text" name="prc" id="price" value="R"/><br/><br/>
<button type="button" id="insert" class="btn btn-success">Add Product</button>
<button type="button" id="create" class="btn btn-success">Create Table</button>
<button type="button" id="remove" class="btn btn-danger">Delete Table</button>
<button type="button" id="list" class="btn btn-success">Display Products</button><br/>
<p><small><b>Note:</b> Table must be created first before performing any transaction.</small></p>
</form>
我正在使用Web SQL
这是我的JavaScript代码
function loadData(){
$("#itemlist").children().remove();
db.transaction(function(transaction){
var sql="SELECT * FROM products ORDER BY id DESC";
transaction.executeSql(sql,undefined,function(transaction,result){
if(result.rows.length){
for(var i=0;i<result.rows.length;i++){
var rows=result.rows.product(i);
var id=row.id;
var product=row.product;
var quantity=row.quantity;
var price=row.price;
$("#itemlist").append('<tr id="del'+id+'"><td>'+id+'</td><td>'+product+'</td><td id="newqty'+id+'">'+quantity+'</td><td id="newprice'+id+'">'+price+'</td><td><a href="#" class="btn btn-danger deleteitem" data-id="'+id+'">Delete</a> <a href="#" class="btn btn-primary updateitem" data-id="'+id+'">Update</a></td></tr>');
}
}else{
$("#itemlist").append('<tr><td colspan="4" align="center">No Product Found</td></tr>');
}
},function(transaction,err){
alert('No table found. Click on "Create Table" to create table now');
})
})
};
我一直在试着调试这个没有运气,我试着看到类似的问题,但他们不工作。
var rows=result.rows.product(i);
上面是显示错误消息的行。
更改此行
var rows = result.rows.product(i);
与
var row = result.rows.item(i);