问题:
RequireJS似乎没有和Breeze玩得很好。
我有一个错误如下:
Unable to initialize OData. Needed to support remote OData services这通常意味着datajs没有加载,需要在之前添加到页面中。但是,我已经在RequireJS中这样做了--或者至少我认为我做到了,但是我的配置中可能有错误或遗漏。
My Config:
main.js包含以下内容:
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
});测试模块(非常简单的测试页面),如下所示:
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>如您所见,我已经将datajs和q指定为的依赖项。我在这里错过了什么?
编辑
我通过FireBug检查了HTML,如您所见,q和datajs似乎都是在之前加载的。所以我在这里完全糊涂了。

发布于 2015-07-22 01:49:52
我在这里发现了答案:DataJS library not loading in RequireJS
显然,我们需要为同一个js文件引用两个单独的对象.如下所示:
'paths': {
'datajs': '../datajs-1.1.3',
'OData': '../datajs-1.1.3',
},
'shim': {
'OData':['datajs']
}https://stackoverflow.com/questions/31541730
复制相似问题