Connect to OData with dynamic metadata
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
$data.service("http://jaydata.org/examples/Northwind.svc", function(contextFactory, contextType) {
//downloads $metadata and runs jaysvcutil for javascript on it
//context instances are a means of isolation, for parallel writes you'll need multiple contexts
//therefore $data.service provides you with a factory
var northwind = contextFactory();
//if you include jquery you can use the promise interface
$.when(northwind.ready).then(function() {
northwind.Categories.forEach(function(category) {
$('#output').append('<div>' + category.Category_Name + '</div>');
});
});
//w/o jquery
//northwind.onReady(function() { work with northwind here })
});