Problem:
RequireJS does not seem to be playing nicely with Breeze.
I have an error as follows:
Unable to initialize OData. Needed to support remote OData services
This generally means that datajs is not loaded and needs to be added to the page before breeze. However, I have done this with RequireJS - or at least I think I have, but may have something wrong or missing in my config.
My Config:
main.js contains the following:
var paths = {
'text': '../text',
'durandal': '../durandal',
'plugins': '../durandal/plugins',
'transitions': '../durandal/transitions',
'breeze': '../breeze.debug',
'datajs': '../datajs-1.1.3',
'q': '../q',
};
var shim = {
'datajs': ['jquery'],
'breeze': ['jquery', 'datajs', 'q']
};
requirejs.config({
paths: paths,
shim: shim
});
Test module (a very simple test page), as follows:
JS:
define(['jquery', 'knockout', 'datajs', 'q', 'breeze'], function ($, ko, datajs, q, breeze) {
return {
people: ko.observableArray([]),
attached: function () {
breeze.config.initializeAdapterInstances({ dataService: "OData" });
var manager = new breeze.EntityManager('/odata');
var query = new breeze.EntityQuery()
.from("People")
.orderBy("Name asc");
manager.executeQuery(query).then(function (data) {
this.people([]);
$(data.httpResponse.data.results).each(function () {
var current = this;
this.people.push({ Id: current.Id, Name: current.Name });
});
}).fail(function (e) {
alert(e);
});
}
};
});
HTML:
<section>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody data-bind="foreach: people">
<tr>
<td data-bind="text: Id"></td>
<td data-bind="text: Name"></td>
</tr>
</tbody>
</table>
</section>
As you can see, I have specified datajs and q as dependencies of breeze. So, what am I missing here?
EDIT
I inspected the HTML via FireBug and as you can see, both q and datajs seem to be loaded before breeze. So I am totally confused here.