0

我在 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
});

有任何想法吗?

4

1 回答 1

1

这段代码中只有一件事需要修复:应该计算ID 字段而不是required。更改后,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();
});

这能解决您的问题吗?

于 2013-05-10T10:52:28.510 回答