本文介绍了Jaydata indexedDb数据库创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jayData上遇到此问题:我尝试创建这个简单的数据库:
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',
});
哪个效果很好.但是当我只是将数据库类型切换为indexxedDb时,它什么也没做.
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
});
有什么想法吗?
推荐答案
此代码中只有一件事需要解决:ID字段应计算,而不是必填 >.更改后,JayData将为您自动生成ID.
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?
这篇关于Jaydata indexedDb数据库创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!