Jaydata indexedDb database creation issues

人走茶凉 提交于 2019-12-25 18:34:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!