我在jayData上有这个问题: 我尝试创建这个简单的数据库:
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',
});
完美无缺。但是当我只是将数据库类型切换到indexxedDb时,它什么也没做。
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
});
有什么想法吗?
答案 0 :(得分:1)
此代码中只有一件事需要修复:ID字段应为计算,而不是必需。一旦你改变它,JayData将为你自动生成ID。
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();
});
这会解决您的问题吗?