Define type, save an item, readAll
by kougiland
HTML
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://include.jaydata.org/jaydata.js"></script>
<h3>This example defines a Task entity then saves an instance and reads all instances back</h3>
<p>Open the developer console in Chrome, and see the databases on the Resources tab</p>
<div id="output">
</div>
CSS
body {
font-family: Segoe UI Light
}
JavaScript
var Task = $data.define("Task", {
Todo: String,
Completed: Boolean,
Priority: Number,
DueDate: Date
});
Task.save({
Todo: "Include script resources",
Completed: false,
Priority: 1,
DueDate: new Date()
}).then(function() {
//save() is async and returns a jQuery promise
Task.readAll().then(function(taskArray) {
//readAll() is async and returns a jQuery promise
taskArray.forEach(function(task) {
$('#output').append(JSON.stringify(task) + "<br />")
});
});
});