alasql - 未定义的数据源编号 0,简单 Javascript 对象作为源然后查询,给出此错误
alasql - Data source number 0 in undefined ,simple Javascript object as source then query, gives this error
<script src="https://cdn.jsdelivr.net/alasql/0.3/alasql.min.js"></script>
var ProductList = JSON.parse('[{"ProductID":1,"ProductName":"Shoes"},{"ProductID":2,"ProductName":"Chocolate"}]');
alasql("CREATE TABLE Products (ProductID INT, ProductName string)");
alasql.tables.Products = ProductList; // when inspect, the table is present
var x = alasql("SELECT * FROM Products order by ProductID"); //throws error
我解决了。
db.tables.Products.data - 我缺少数据。
不需要解析。
var db = new alasql.Database();
db.exec("CREATE TABLE Products (ProductID INT, ProductName string)");
var ProductList = [{"ProductID":1,"ProductName":"Shoes"},{"ProductID":2,"ProductName":"Chocolate"}];
db.tables.Products.data = ProductList;
var res = db.exec("SELECT * FROM Products");
根据您分享的图片,我看到您没有提供json数据源。
您可以通过...修复它
var x=alasql("Select * FROM ? ORDER BY ProductID",[Products])
<script src="https://cdn.jsdelivr.net/alasql/0.3/alasql.min.js"></script>
var ProductList = JSON.parse('[{"ProductID":1,"ProductName":"Shoes"},{"ProductID":2,"ProductName":"Chocolate"}]');
alasql("CREATE TABLE Products (ProductID INT, ProductName string)");
alasql.tables.Products = ProductList; // when inspect, the table is present
var x = alasql("SELECT * FROM Products order by ProductID"); //throws error
我解决了。
db.tables.Products.data - 我缺少数据。
不需要解析。
var db = new alasql.Database();
db.exec("CREATE TABLE Products (ProductID INT, ProductName string)");
var ProductList = [{"ProductID":1,"ProductName":"Shoes"},{"ProductID":2,"ProductName":"Chocolate"}];
db.tables.Products.data = ProductList;
var res = db.exec("SELECT * FROM Products");
根据您分享的图片,我看到您没有提供json数据源。
您可以通过...修复它
var x=alasql("Select * FROM ? ORDER BY ProductID",[Products])