问题
I have this problem on jayData: I try to create this simple database:
var x=$data.Entity.extend("Person",
{
ID: {type: "int", key:true, required: true},
Name: {type: "string", required: true}
});
$data.EntityContext.extend("PersonDatabase",
{
People: {type: $data.EntitySet, elementType: Person}
});
var DB1=new PersonDatabase({
provider: 'webSql',
databaseName:'DB1',
});
Which works perfectly. But when I simply switch the database type to indexxedDb, it doesn't do anything.
var x=$data.Entity.extend("Person",
{
ID: {type: "int", key:true, required: true},
Name: {type: "string", required: true}
});
$data.EntityContext.extend("PersonDatabase",
{
People: {type: $data.EntitySet, elementType: Person}
});
var DB1=new PersonDatabase({
provider: 'indexedDb',
databaseName:'DB1',
version: 1
});
Any ideas?
回答1:
There is only one thing to fix in this code: the ID field should be computed instead of required. Once you change it, JayData will autogenerate the ID for you.
var x=$data.Entity.extend("Person",
{
Id: {type: "int", key:true, computed: true},
Name: {type: "string", required: true}
});
$data.EntityContext.extend("PersonDatabase",
{
People: {type: $data.EntitySet, elementType: Person}
});
var DB1=new PersonDatabase({ provider: 'indexedDb', databaseName:'DB1', version: 1 });
DB1.onReady(function() {
DB1.People.add({ Name: 'Jay Data'});
DB1.saveChanges();
});
Does this fix your issue?
来源:https://stackoverflow.com/questions/16478650/jaydata-indexeddb-database-creation-issues