提问者:小点点

我正在尝试检索表数据,但遇到以下错误:uncattle typeerror:result.rows.product不是products.html:134中的函数


<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);

上面是显示错误消息的行。


共1个答案

匿名用户

更改此行

var rows = result.rows.product(i);

var row = result.rows.item(i);