events post
by JayData
HTML
<script src="http://include.jaydata.org/jaydata.js"></script>
JavaScript
//Define the Category entity with the Products array property
$data.Entity.extend("Category", {
Id: { key: true, type: "int", computed: true },
Name: { type: "string", required: true },
Products: { type: Array, elementType: "Product", inverseProperty: "Category" }
});
//Define the Product entity with the Category reference
$data.Entity.extend("Product", {
Id: { key: true, type: "int", computed: true },
Name: { type: "string", required: true },
Name2: { type: "string"},
Category: { type: "Category", inverseProperty: "Products" }
});
//Define our context with typed EntitySets (tables), which will provide access to our database
$data.EntityContext.extend("NorthwindContext", {
Categories: { type: $data.EntitySet, elementType: Category },
Products: { type: $data.EntitySet, elementType: Product }
});
//Initialize a WebSQL/SQLite database connection with the defined schema
var nw = new NorthwindContext({ provider: "webSql", databaseName: "northwind" });
nw.onReady(function () {
var newProduct = new Product({ Name: 'Beer' });
newProduct.propertyChanging.attach(function(sender, eventData){
console.log('eventData', eventData);
})
//nw.Products.add(newProduct);
/*
nw.saveChanges(function () {
nw.Products.toArray(function() {
console.log('read');
})
});
*/
});