Simple Item Store API with OData
by JayData
HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://include.jaydata.org/jaydata.min.js"></script>
<script src="http://include.jaydata.org/datajs-1.0.3.js"></script>
<div id="output"></div>
JavaScript
//this is a simplified API to work with 'just a couple of types with a couple of fields'
var Category = $data.define("Category", {
Category_ID: { type: 'int', key: true, computed: true},
Category_Name: String
}).setStore('default', { provider: 'oData', dataSource: 'http://jaydata.org/examples/Northwind.svc/Categories'});
Category.readAll().then(function(items) {
items.forEach(function(category) {
$('#output').append('<div>' + category.Category_Name + '</div>');
});
return
//to create/update/remove items without entity context use entity type as facade
Category.save({Category_Name: 'abc'}).then(function(category) {
alert('new items saved:' + category.Category_ID);
});
//or
//var category = new Category({...});
//category.save().then(...);
});