使用JayData进行基本数据存储 [英] Basic data storage with JayData
本文介绍了使用JayData进行基本数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试实现我的第一个基于JayData的应用程序。我需要我的HTML5 / JavaScript应用程序来存储客户端的复杂数据(主要是一对多关系)。
I try to implement my first JayData based application. I need my HTML5/JavaScript app to store complex data client-side (mostly one-to-many relations).
我的模型看起来像这样(对不起,如果名字是不太明确):
My model looks like this (sorry if the names are not very explicit):
我试图用JayData翻译它,如果我错了,请纠正我:
I've tried to translate it with JayData, correct me if I'm wrong:
$data.Entity.extend("Test", {
Id: { type: "int", key: true, computed: true },
Name: { type: "string", required: true, maxLength: 200 },
Chapters: { type: Array, elementType: "Chapter", inverseProperty: "Test" }
});
$data.Entity.extend("Chapter", {
Id: { type: "int", key: true, computed: true },
Name: { type: String, required: true, maxLength: 200 },
Test: {type: "Test", inverseProperty: "Chapters" },
Checks: { type: Array, elementType: "Check", inverseProperty: "Chapter" }
});
$data.Entity.extend("Check", {
Id: { type: "int", key: true, computed: true },
Name: { type: String, required: true, maxLength: 200 },
Status: { type: "int", required: true },
Chapter: { type: Chapter, inverseProperty: "Checks" }
});
$data.EntityContext.extend("CheckDb", {
Tests: { type: $data.EntitySet, elementType: Test },
Chapters: { type: $data.EntitySet, elementType: Chapter },
Checks: { type: $data.EntitySet, elementType: Check }
});
编辑
如何填写所有表格?首先,我尝试过:
How to fill all tables? To start, I've tried:
var myDB = new CheckDb({
name: 'local', databaseName: 'CheckDatabase'
});
myDB.onReady(function() {
myDB.Tests.add({
Name: "Test 1"
});
myDB.saveChanges();
});
但是如果我想添加章节
和检查
到我的测试
?
But what if I want to add Chapters
and Checks
to my Test
?
谢谢
推荐答案
好的,我终于找到了它自己:
Okay I've finally found it by myself:
myDB.onReady(function() {
var check = new Check({Name: "Check 1", Status: 1});
var chapter = new Chapter({Name: "Chapter 1"});
chapter.Checks = new Array();
chapter.Checks.push(check);
var myTest = myDB.Tests.add({
Name: "Test 1",
Chapters: [chapter]
});
myDB.saveChanges();
});
这并不难:)
这篇关于使用JayData进行基本数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文